Pagini recente » Cod sursa (job #404567) | Cod sursa (job #2115433) | Cod sursa (job #3041671) | Cod sursa (job #1229313) | Cod sursa (job #562709)
Cod sursa(job #562709)
var c:array[1..15000] of longint;
n:word;
procedure update(poz:word;val:longint);
begin
while poz<=n do
begin
inc(c[poz],val);
inc(poz,(poz xor (poz-1))and poz);
end;
end;
function query(poz:word):longint;
var rez:longint;
begin
rez:=0;
while poz>0 do
begin
inc(rez,c[poz]);
dec(poz,(poz xor (poz-1))and poz);
end;
query:=rez;
end;
procedure rezolva;
var i,x,y,m:longint;
op:byte;
begin
assign(input,'datorii.in');reset(input);
readln(n,m);
assign(output,'datorii.out');rewrite(output);
for i:=1 to n do
begin
read(x);
update(i,x);
end;
for i:=1 to m do
begin
readln(op,x,y);
if op=0 then update(x,-y)
else writeln(query(y)-query(x-1));
end;
close(input);close(output);
end;
begin
rezolva;
end.