Pagini recente » Cod sursa (job #2718450) | Cod sursa (job #652722) | Cod sursa (job #815610) | Cod sursa (job #431795) | Cod sursa (job #197471)
Cod sursa(job #197471)
var v:array[1..40010]of longint;
n,i,j,k,m,o,a,b,c,l,s:longint;
f1,f2:text;
procedure plata(p,r:longint);
var q:longint;
begin
v[l]:=v[l]-c;
q:=(p+r)div 2;
if p<r then begin if b<=q then begin l:=l*2;
plata(p,q);
end
else begin l:=l*2+1;
plata(q+1,r);
end;
end;
end;
procedure cauta(p,r,w:longint);
var q:longint;
begin
q:=(p+r)div 2;
if(b<=p)and(r<=c)then s:=s+v[w]
else begin if b<=q then cauta(p,q,w*2);
if c>q then cauta(q+1,r,w*2+1);
end;
end;
begin
assign(f1,'datorii.in');
reset(f1);
assign(f2,'datorii.out');
rewrite(f2);
readln(f1,n,m);
o:=1;
while o<n do
o:=o*2;
for i:=1 to n do
read(f1,v[i+o-1]);
for i:=o*2-1 downto 2 do
v[i div 2]:=v[i div 2]+v[i];
for i:=1 to m do
begin
read(f1,a,b,c);
if a=0 then begin l:=1;
plata(1,o);
end
else begin l:=1;
s:=0;
cauta(1,o,l);
writeln(f2,s);
end;
end;
close(f1);
close(f2);
end.