Cod sursa(job #108440)

Utilizator h_istvanHevele Istvan h_istvan Data 22 noiembrie 2007 18:51:42
Problema Datorii Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.95 kb
program datorii;
var f,fout:Text;
    n,m,i,t,a,b,c:longint;
    v:array[0..15000] of longint;

procedure hozzaad(index,ertek:longint);
var t:longint;
begin
     t:=index;
     while(t<=n) do
     begin
          v[t]:=v[t]+ertek;
          t:=t+((t xor (t-1)) and t);
     end;
end;

function ossz(index:longint):longint;
var t,o:longint;
begin
     o:=0;
     t:=index;
     while(t > 0) do
     begin
          o:=o+v[t];
          t:=t-((t xor (t-1)) and t);
     end;
     ossz:=o;
end;

begin
     assign(f,'datorii.in');
     reset(f);
     readln(f,n,m);
     for i:=1 to n do
     begin
          read(f,t);
          hozzaad(i,t);
     end;
     readln(f);
     assign(fout,'datorii.out');
     rewrite(fout);
     for i:=1 to m do
     begin
          readln(f,a,b,c);
          if(a=0) then hozzaad(b,(-1)*c)
                  else writeln(fout,ossz(c)-ossz(b-1));
     end;
     close(fout);
     close(f);
end.