Pagini recente » Cod sursa (job #3212105) | Cod sursa (job #156605) | Cod sursa (job #2120126) | Cod sursa (job #647389) | Cod sursa (job #528609)
Cod sursa(job #528609)
type vector=array[0..15000] of longint;
var v,b,c:vector;
n,m,i,j,x,y,q:longint;
f,t:text;
function suma(p:longint):longint;
var t:longint;
begin
suma:=0;
if p>0 then
begin
t:=c[b[p]];
while p-t>=0 do
begin
suma:=suma+v[p];
dec(p,t);
if p>0 then t:=c[b[p]];
end;
end;
end;
procedure modifica(x,y:longint);
var t:longint;
begin
t:=c[b[x]];
v[x]:=v[x]-y;
while x+t<=n do
begin
inc(x,t);
t:=c[b[x]];
v[x]:=v[x]-y;
end;
end;
begin
assign(f,'datorii.out');
rewrite(f);
assign(t,'datorii.in');
reset(t);
readln(t,n,m);
c[0]:=1;
for i:=1 to 15 do
c[i]:=c[i-1]*2;
for i:=1 to n do
if b[i]=0 then
begin
j:=i;
while j<=n do
begin
b[j*2]:=b[j]+1;
j:=j*2;
end;
end;
for i:=1 to n do
begin
read(t,q);
v[i]:=q+suma(i-1)-suma(i-c[b[i]]);
end;
for i:=1 to m do
begin
readln(t,j,x,y);
if j=1 then writeln(f,suma(y)-suma(x-1))
else modifica(x,y);
end;
close(t);
close(f);
end.