Pagini recente » Cod sursa (job #3196079) | Cod sursa (job #240941) | Cod sursa (job #1592325) | Cod sursa (job #2259563) | Cod sursa (job #842595)
Cod sursa(job #842595)
{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;
buf1,buf2:array[1..1 shl 17]of char;
begin
assign(input,'datorii.in'); reset(input); settextbuf(input,buf1);
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); settextbuf(output,buf2);
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.