Cod sursa(job #195648)

Utilizator theratmantheratman theratman Data 20 iunie 2008 13:55:02
Problema Datorii Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.87 kb
var c:array[1..150000]of longint;
    f,g:text;
    n,m,i,s1,s2,st,dr,poz,cod,ind,val:longint;
begin
assign(f,'datorii.in');reset(f);
assign(g,'datorii.out');rewrite(g);
read(f,n,m);
for i:=1 to n do read(f,c[i]);
for i:=1 to m do begin
 read(f,cod);
 if cod=0 then begin
  read(f,ind,val);
  poz:=0;
  while ind<=n do begin
   c[ind]:=c[ind]+val;
   while ind and (1 shl poz)=0 do inc(poz);
   ind:=ind+1 shl poz;
   inc(poz);
  end;
 end
  else begin
   read(f,st,dr);
   s1:=0;
   poz:=0;
   while dr>0 do begin
    s1:=s1+c[dr];
    while dr and (1 shl poz)=0 do inc(poz);
    dr:=dr-1 shl poz;
    poz:=poz+1;
   end;
   dec(st);
   s2:=0;
   poz:=0;
   while st>0 do begin
    s2:=s2+c[st];
    while st and (1 shl poz)=0 do inc(poz);
    st:=st-1 shl poz;
    inc(poz);
   end;
   writeln(g,s1-s2);
  end;
end;
close(f);
close(g);
end.