Cod sursa(job #562480)

Utilizator andrei31Andrei Datcu andrei31 Data 23 martie 2011 09:51:30
Problema Datorii Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.91 kb
var t:array[1..1 shl 15] of longint;


procedure update(nod,l,r,p,v:longint);
var m:longint;
begin
m:=(l+r) shr 1;
t[nod]:=t[nod]-v;
if l<r then
 if p<=m then update(nod shl 1,l,m,p,v)
  else update(nod shl 1+1,m+1,r,p,v);
end;

function query(nod,l,r,a,b:longint):longint;
var tt,m:longint;
begin
tt:=0;
if (a<=l) and (r<=b) then tt:=t[nod]
 else
   begin
   m:=(l+r) shr 1;
   if a<=m then tt:=tt+query(nod shl 1,l,m,a,b);
   if m<b then tt:=tt+query(nod shl 1+1,m+1,r,a,b);
   end;
query:=tt;
end;

procedure citire;
var i,n,m,x,y,op:longword;
begin
assign(input,'datorii.in');reset(input);
readln(n,m);
for i:=1 to n do
 begin
 read(x);
 update(1,1,n,i,-x);
 end;
assign(output,'datorii.out');rewrite(output);
for i:=1 to m do
 begin
 readln(op,x,y);
 if op=0 then
   update(1,1,n,x,y)
    else writeln(query(1,1,n,x,y));
 end;
close(input);close(output);
end;

begin
citire;
end.