Pagini recente » Cod sursa (job #1596850) | Cod sursa (job #850066) | Cod sursa (job #1096687) | Cod sursa (job #328821) | Cod sursa (job #744150)
Cod sursa(job #744150)
const val=16384;
var t:array[1..val*2] of longint;
i,n,m,x,y,z,mij:longint;
bi,bo:array[1..1 shl 17] of char;
{
function maxim(a,b:longword):longword;
begin if a>b then maxim:=a else maxim:=b end;
}
procedure actualizare(fp,fx:longint);
Begin
t[fp]:=t[fp]+fx;
fp:=fp div 2;
while fp<>0 do
begin
t[fp]:=t[2*fp]+t[2*fp+1];
fp:=fp div 2;
end;
End;
procedure cauta(s,d,niv:longint);
Begin
mij:=(s+d) div 2;
if (s>=x) and (d<=y) then z:=t[niv]+z
else
begin
if x<=mij then cauta(s,mij,niv*2);
if y>=mij+1 then cauta(mij+1,d, niv*2+1);
end;
End;
BEGIN
assign(input,'datorii.in');
settextbuf(input,bi);
reset(input);
assign(output,'datorii.out');
settextbuf(output,bo);
rewrite(output);
readln(n,m);
for i:=1 to n do
begin
read(x);
actualizare(val+i-1, x)
end;
for i:=1 to m do
begin
readln(z,x,y);
if z=0 then actualizare(val+x-1,-y)
else
begin
z:=0;
cauta(1,n,1);
writeln(z);
end;
end;
close(input);
close(output);
END.