Cod sursa(job #252249)

Utilizator valytgjiu91stancu vlad valytgjiu91 Data 4 februarie 2009 00:33:08
Problema Arbori de intervale Scor 50
Compilator fpc Status done
Runda Arhiva educationala Marime 1.42 kb
const nmax=300001;
var f,g:text;
v:array[1..nmax]of longint;
max,pc,uc,a,m,l,nod,poz,b,n,i,j,x:longint;

function maxim(a,b:longint):longint;
begin
if a>b then maxim:=a
   else maxim:=b;
end;
procedure actualizare(nod,st,dr:longint);
var mij:longint;
begin
  if st=dr then
    begin
    v[nod]:=x;
    end
    else
      begin
      mij:=(st+dr)shr 1;
      if poz<=mij then actualizare((nod shl 1),st,mij)
                 else actualizare((nod shl 1)+1,mij+1,dr);
      v[nod]:=maxim(v[2*nod],v[2*nod+1]);
      end;
end;
procedure caut(nod,st,dr:longint);
var mij:longint;
begin
if (pc<=st) and (dr<=uc) then
               begin
               if max<v[nod] then max:=v[nod];
               end
  else
     begin
     mij:=(st+dr)shr 1;
     if (pc<=mij) then caut((nod shl 1),st,mij);
     if (mij<uc) then caut((nod shl 1)+1,mij+1,dr);
     end;
end;
begin
assign(f,'arbint.in');
reset(f);
assign(g,'arbint.out');
rewrite(g);
readln(f,n,m);
for i:=1 to n do
begin
read(f,x);
poz:=i;
actualizare(1,1,n);
end;

for i:=1 to m do
   begin
      readln(f,x,a,b);
      if x=1 then
             begin
             poz:=a;
             x:=b;
             actualizare(1,1,n);
             end
             else
             begin
             max:=0;
             pc:=a;
             uc:=b;
             caut(1,1,n);
             writeln(g,max);
             end;
      end;
close(g);
end.