Cod sursa(job #543014)

Utilizator chestiaproblema de trimis chestia Data 27 februarie 2011 13:56:17
Problema Arbori de intervale Scor 40
Compilator fpc Status done
Runda Arhiva educationala Marime 1.11 kb
var  arb:array[1..200002]of longint;
     m,n,i,poz,x,a,b,max:longint;
     f,g:text;

function maxim(a,b:longint):longint;
begin
if a>b then maxim:=a else maxim:=b;
end;

procedure update(nod,l,r:longint);
var mij:longint;
begin
if (poz=l)and(poz=r) then begin
    arb[nod]:=x;
    exit;
    end;
mij:=(l+r)div 2;
if poz<=mij then update(2*nod,l,mij);
if poz>mij then update(2*nod+1,mij+1,r);
arb[nod]:=maxim(arb[nod*2],arb[2*nod+1]);
end;


procedure care(nod,l,r:longint);
var mij:longint;
begin
if (l>=a) and (r<=b) then begin
   if max<arb[nod] then max:=arb[nod];
   exit;
   end;
mij:=(l+r)div 2;
if mij>=a then care(2*nod,l,mij);
if mij<b then care(2*nod+1,mij+1,r);
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;
 update(1,1,n);
 end;

readln(f);

for i:=1 to m do begin
    readln(f,x,a,b);
    if x=1 then begin
     x:=b;
     poz:=a;
     update(1,1,n);
     end else begin
     max:=-1;
     care(1,1,n);
     writeln(g,max);
     end;
end;
close(f);
close(g);
end.