Pagini recente » Cod sursa (job #1923153) | Cod sursa (job #947300) | Cod sursa (job #2184982) | Cod sursa (job #1631375) | Cod sursa (job #588802)
Cod sursa(job #588802)
var a:array[1..100000]of longint;
n,m:longint;
procedure modif(x,k:longint);
begin
while x<=n do
begin
inc(a[x],k);
inc(x,(x xor (x-1))and x);
end;
end;
function suma(x:longint):longint;
var k:longint;
begin
k:=0;
while x>0 do
begin
inc(k,a[x]);
dec(x,(x xor (x-1))and x);
end;
suma:=k;
end;
function poz(x:longint):longint;
var i,s:longint;
begin
poz:=-1; s:=0;
for i:=1 to n do
begin
s:=s+a[i];
if s=x then begin poz:=i; break; end;
end;
end;
procedure calc;
var i,x,y,p:longint; f,t:text;
begin
assign(f,'grader_test1.in');
reset(f);
assign(t,'aib.out');
rewrite(t);
readln(f,n,m);
for i:=1 to n do
begin
read(f,p);
modif(i,p);
end;
readln(f);
for i:=1 to m do
begin
read(f,p);
if p=0 then begin readln(f,x,y); modif(x,y); end else
if p=1 then begin readln(f,x,y); writeln(t,suma(y)-suma(x-1)); end else
begin readln(f,x); writeln(t,poz(x)); end;
end;
close(t);
close(f);
end;
begin
calc;
end.