Pagini recente » Borderou de evaluare (job #469328) | Cod sursa (job #253995) | Cod sursa (job #108436)
Cod sursa(job #108436)
program datorii;
var f,fout:Text;
n,m,i,t,a,b,c:longint;
v:array[0..15000] of longint;
function bin(x:longint):longint;
var h:longint;
begin
h:=1;
while(x mod (2*h) = 0) do h:=2*h;
bin:=h;
end;
procedure hozzaad(index,ertek:longint);
var t:longint;
begin
t:=index;
while(t<=n) do
begin
v[t]:=v[t]+ertek;
t:=t+bin(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-bin(t);
end;
ossz:=o;
end;
function osszeg(k,v:longint):longint;
begin
osszeg:=ossz(v)-ossz(k-1);
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,osszeg(b,c));
end;
close(fout);
close(f);
end.