Cod sursa(job #562709)

Utilizator andrei31Andrei Datcu andrei31 Data 23 martie 2011 18:47:11
Problema Datorii Scor 20
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.75 kb
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.