Pagini recente » Cod sursa (job #2810964) | Cod sursa (job #2423747) | Cod sursa (job #1729891) | Cod sursa (job #1880481) | Cod sursa (job #530714)
Cod sursa(job #530714)
var a,v:array[0..15000] of longint;
n,m,i,j,x,y:longint;
f,t:text;
function suma(p:longint):longint;
begin
suma:=0;
while p>0 do
begin
suma:=suma+v[p];
dec(p,(p xor (p and (p-1))));
end;
end;
procedure modifica(x,y:longint);
begin
while x<=n do
begin
v[x]:=v[x]-y;
inc(x,(x xor (x and (x-1))));
end;
end;
begin
assign(f,'datorii.out');
rewrite(f);
assign(t,'datorii.in');
reset(t);
readln(t,n,m);
for i:=1 to n do
begin
read(t,a[i]);
for j:=i-(i xor (i and (i-1)))+1 to i do
v[i]:=v[i]+a[j];
end;
for i:=1 to m do
begin
readln(t,j,x,y);
if j=0 then modifica(x,y)
else if x=1 then writeln(f,suma(y))
else writeln(f,suma(y)-suma(x-1));
end;
close(t);
close(f);
end.