Cod sursa(job #251109)

Utilizator valytgjiu91stancu vlad valytgjiu91 Data 1 februarie 2009 21:48:22
Problema Arbori indexati binar Scor 0
Compilator fpc Status done
Runda Arhiva educationala Marime 0.69 kb
var f,g:text;
v,c:array[1..10000] of longint;
n,m,i,j,x,s,y,p:longint;
begin
assign(f,'aib.in');
reset(f);
assign(g,'aib.out');
rewrite(g);
readln(f,n,m);
for i:=1 to n do
begin
read(f,v[i]);
c[i]:=c[i-1]+v[i];
end;

for i:=1 to m do
begin
  read(f,p);
  if p=2 then
  begin
       read(f,x);

        for j:=1 to n do
         if c[j]=x then begin writeln(g,j); break;end;
  end
  else
  begin
  read(f,x,y);
  if p=1 then
       begin
         s:=c[y]-c[x-1];
         writeln(g,s);
         end
         else
         begin
         c[x]:=c[x]+y;
         for j:=x to n do
               c[j]:=c[j]+y;
         v[x]:=v[x]+y
         end
   end;
end;
close(g);
end.