Pagini recente » Cod sursa (job #2181368) | Cod sursa (job #2236490) | Cod sursa (job #1056925) | Cod sursa (job #2225188) | Cod sursa (job #2120)
Cod sursa(job #2120)
program datorii;
var a,c:array[1..15000] of qword;
n:1..15000;
i,p,q,poz:longint;
cod:0..1;
k,j:qword;
f,g:text;
begin
assign(f,'datorii.in');
reset(f);
readln(f,n,i);
for i:=1 to n do
read(f,a[i]);
readln(f);
i:=0;
repeat
i:=i+1;
poz:=0;
if (i and 1)=1 then p:=1
else begin
while (i and (2 shl poz))=0 do
poz:=poz+1;
p:=i-(2 shl poz)+1;
end;
c[i]:=0;
for j:=p to i do
c[i]:=c[i]+a[j];
until i=n;
assign(g,'datorii.out');
rewrite(g);
repeat
readln(f,cod,p,q);
if cod=0 then begin
poz:=0;
if (p+1<=n)and(p and 1=1) then
begin
c[p]:=c[p]-q;
p:=p+1;
end;
while p<=n do
begin
c[p]:=c[p]-q;
while p and (2 shl poz)=0 do
poz:=poz+1;
p:=p+(2 shl poz);
poz:=poz+1;
end;
end
else begin
poz:=0;
k:=0;
if q and 1=1 then begin
k:=k+c[q];
q:=q-1;
end;
while q>0 do begin
k:=k+c[q];
while q and (2 shl poz)=0 do
poz:=poz+1;
q:=q-(2 shl poz);
poz:=poz+1;
end;
poz:=0;
j:=0;
p:=p-1;
if p and 1=1 then begin
j:=j+c[p];
p:=p-1;
end;
while p>0 do begin
j:=j+c[p];
while p and (2 shl poz)=0 do
poz:=poz+1;
p:=p-(2 shl poz);
poz:=poz+1;
end;
writeln(g,k-j);
end;
until eof(f);
close(f);
close(g);
end.