Pagini recente » Cod sursa (job #68651) | Cod sursa (job #897823) | Cod sursa (job #3188413) | Cod sursa (job #1231223) | Cod sursa (job #343113)
Cod sursa(job #343113)
var v:array[1..15000] of longint;
m,n,i,x,y,z:longint;
f,g:text;
function zeros(p:longint):longint;
begin
zeros:=p and ((p-1) xor p);
end;
procedure update(poz,val:longint);
begin
while poz<=n do
begin
inc(v[poz],val);
inc(poz,zeros(poz));
end;
end;
function sum(hi:longint):longint;
var s:longint;
begin
s:=0;
while hi>0 do
begin
inc(s,v[hi]);
dec(hi,zeros(hi));
end;
sum:=s;
end;
begin
assign(f,'datorii.in');
assign(g,'datorii.out');
reset(f);rewrite(g);
readln(f,n,m);
for i:=1 to n do
begin
read(f,x);
update(i,x);
end;
readln(f);
for i:=1 to m do
begin
readln(f,x,y,z);
if x=0 then
update(y,-z)
else
writeln(g,sum(z)-sum(y-1));
end;
close(f);close(g);
end.