Pagini recente » Cod sursa (job #603765) | Cod sursa (job #654146) | Cod sursa (job #993475) | Cod sursa (job #914052) | Cod sursa (job #165422)
Cod sursa(job #165422)
const nmax=15001;
var c:array[1..nmax]of longint;
n,x,y,z:integer;
m,i:longint;
f,g:text;
procedure update(poz,val:integer);
var k:integer;
begin
k:=poz;
while (k<=n) do begin
c[k]:=c[k]+val;
k:=(k or (k-1))+1;
end;
end;
function query(ld:integer):longint;
var k:integer;
s:longint;
begin
k:=ld;s:=0;
while (k>0) do begin
s:=s+c[k];
k:=k and (k-1);
end;
query:=s;
end;
begin {main}
assign(input,'datorii.in');reset(input);
assign(output,'datorii.out');rewrite(output);
readln(n,m);
for i:=1 to n do c[i]:=0;
for i:=1 to n do begin read(x); update(i,x); end;
for i:=1 to m do begin
readln(x,y,z);
if x=0 then update(y,-z)
else writeln(query(z)-query(y-1));
end;
close(input);close(output);
end.