Cod sursa(job #744146)

Utilizator RadioactivMihai Preguza Radioactiv Data 7 mai 2012 18:55:43
Problema Datorii Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.15 kb
const val=131072;
var t:array[1..val*2] of longword;
    i,n,m,x,y,z,mij:longword;
    bi,bo:array[1..1 shl 17] of char;
{
function maxim(a,b:longword):longword;
begin if a>b then maxim:=a else maxim:=b end;
                                     }


procedure actualizare(fp,fx:longint);
Begin
  t[fp]:=t[fp]+fx;
  fp:=fp div 2;
  while fp<>0 do
    begin
      t[fp]:=t[2*fp]+t[2*fp+1];
      fp:=fp div 2;
    end;
End;


procedure cauta(s,d,niv:longint);
Begin
  mij:=(s+d) div 2;
  if (s>=x) and (d<=y) then z:=t[niv]+z
  else
  begin
    if x<=mij then cauta(s,mij,niv*2);
    if y>=mij+1 then cauta(mij+1,d, niv*2+1);
  end;
End;

BEGIN
  assign(input,'datorii.in');
  settextbuf(input,bi);
  reset(input);
  assign(output,'datorii.out');
  settextbuf(output,bo);
  rewrite(output);
  readln(n,m);
  for i:=1 to n do
    begin
      read(x);
      actualizare(val+i-1, x)
    end;
  for i:=1 to m do
    begin
      readln(z,x,y);
      if z=0 then actualizare(val+x-1,-y)
      else
      begin
        z:=0;
        cauta(1,n,1);
        writeln(z);
      end;
    end;
  close(input);
  close(output);
END.