Pagini recente » Cod sursa (job #2389414) | Cod sursa (job #2611151) | Cod sursa (job #3204825) | Cod sursa (job #1612637) | Cod sursa (job #995151)
Cod sursa(job #995151)
program datorii;
var f,g:text;
v:array[0..15001] of longint;
n,m,i,tip,t,v1:longint;
bufin,bufout:array[1..65000] of byte;
a:longint;
procedure update (i,n,val:longint);
begin
while i<=n do
begin
v[i]:=v[i]+val;
i:=i+(-i and i);
end;
end;
function solve(i:longint):longint;
var sum:longint;
begin
sum:=0;
while i>0 do
begin
inc(sum,v[i]);
i:=i-(-i and i);
end;
solve:=sum;
end;
begin
assign (f,'datorii.in'); reset (f);
assign (g,'datorii.out'); rewrite (g);
settextbuf (f,bufin);
settextbuf (g,bufout);
readln (f,n,m);
for i:=1 to n do
begin
read (f,a);
update(i,n,a);
end;
readln (f);
for i:=1 to m do
begin
readln (f,tip,t,v1);
if tip=0 then
begin
update(t,n,-v1);
end
else
begin
writeln (g, solve(v1)-solve(t-1));
end;
end;
close (f); close (G);
end.