Pagini recente » Cod sursa (job #182311) | Cod sursa (job #1022994) | Cod sursa (job #2194334) | Cod sursa (job #2780399) | Cod sursa (job #562710)
Cod sursa(job #562710)
var c:array[1..15000] of longint;
buf1,buf2:array[1..100000] of char;
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');settextbuf(input,buf1);reset(input);
readln(n,m);
assign(output,'datorii.out');settextbuf(output,buf2);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.