Cod sursa(job #842598)

Utilizator t.g.g.tt.g.g.t t.g.g.t Data 27 decembrie 2012 10:40:44
Problema Datorii Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.1 kb
{problema datorii de pe infoarena}
var a:array[1..15000]of longint;  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.