Cod sursa(job #343123)

Utilizator ionutz32Ilie Ionut ionutz32 Data 25 august 2009 09:48:39
Problema Datorii Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.87 kb
var v:array[1..15000] of longint;
m,n,i,x,y,z:longint;
f,g:text;
procedure update(poz,val:longint);
          begin
          while poz<=n do
                begin
                inc(v[poz],val);
                poz:=(poz or (poz-1))+1;
                end;
          end;
function sum(hi:longint):longint;
         var s:longint;
         begin
         s:=0;
         while hi>0 do
               begin
               inc(s,v[hi]);
               hi:=hi and (hi-1);
               end;
         sum:=s;
         end;
begin
assign(f,'datorii.in');
assign(g,'datorii.out');
reset(f);rewrite(g);
readln(f,n,m);
for i:=1 to n do
    begin
    read(f,x);
    update(i,x);
    end;
readln(f);
for i:=1 to m do
    begin
    readln(f,x,y,z);
    if x=0 then
       update(y,-z)
    else
        writeln(g,sum(z)-sum(y-1));
    end;
close(f);close(g);
end.