Cod sursa(job #2122)

Utilizator Programmer01Mierla Laurentiu Marian Programmer01 Data 15 decembrie 2006 23:54:31
Problema Datorii Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.15 kb
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 q:=p to i do
c[i]:=c[i]+a[q];
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.