Pagini recente » Cod sursa (job #1206276) | Cod sursa (job #1964174) | Cod sursa (job #2959277) | Cod sursa (job #1907266) | Cod sursa (job #1213341)
program datorii;
var bufin,bufout:array[1..100000]of byte;
n,m,i,op,x,y:longint;
a:array [1..15000] of longint;
procedure build;
var pow:longint;
begin
pow:=2;
while pow<= n do
begin
i:=pow;
while i<=n do
begin
a[i]:=a[i]+a[i-pow div 2];
i:=i+pow;
end;
pow:=pow*2;
end;
end;
procedure update(pos,val:longint);
var x:longint;
begin
x:=pos;
while x<=n do
begin
a[x]:=a[x]-val;
x:=x+x and -x;
end;
end;
function query(l,r:longint):longint;
var x,s1,s2:longint;
begin
x:=l-1; s1:=0;s2:=0;
while x>0 do
begin
s1:=s1+a[x];
x:=x-x and -x;
end;
x:=r;
while x>0 do
begin
s2:=s2+a[x];
x:=x-x and -x;
end;
query:=s2-s1;
end;
begin
assign(input,'datorii.in');
reset(input);
settextbuf(input,bufin);
assign(output,'datorii.out');
rewrite(output);
settextbuf(output,bufout);
readln(n,m);
for i:=1 to n do read(a[i]);readln;
build;
for i:=1 to m do
begin
readln(op,x,y);
if op=0 then update(x,y)
else writeln(query(x,y));
end;
close(output);
end.