Pagini recente » Cod sursa (job #335149) | Cod sursa (job #1054915) | Cod sursa (job #2655108) | Cod sursa (job #2902814) | Cod sursa (job #842593)
Cod sursa(job #842593)
{problema datorii de pe infoarena}
var a:array[1..15000]of integer; i,n,m,t,v,p,q,x,s1,s2,x2:longint; ap:byte;
begin
assign(input,'datorii.in'); reset(input);
readln(n,m);
for i:=1 to n do
begin
read(a[i]); s2:=0; s1:=0; x:=0; x2:=0;
x:=(i xor (i-1)) and i; x:=i-x;
while x>0 do begin s1:=s1+a[x]; x2:=(x xor (x-1)) and x; x:=x-x2; end;
x:=i-1;
while x>0 do begin s2:=s2+a[x]; x2:=(x xor (x-1)) and x; x:=x-x2; end;
s2:=s2-s1;
a[i]:=a[i]+s2;
end;
assign(output,'datorii.out'); rewrite(output);
for i:=1 to m do
begin
read(ap);
if ap=0 then
begin
readln(t,v);
while t<=n do begin a[t]:=a[t]-v; x2:=(t xor (t-1)) and t; t:=t+x2 end;
end
else
begin
readln(p,q); p:=p-1; s1:=0; s2:=0;
while p>0 do begin s1:=s1+a[p]; x2:=(p xor (p-1)) and p; p:=p-x2 end;
while q>0 do begin s2:=s2+a[q]; x2:=(q xor (q-1)) and q; q:=q-x2 end;
s2:=s2-s1;
writeln(s2);
end;
end;
close(output);
end.