Cod sursa(job #759857)

Utilizator ctlin04UAIC.VlasCatalin ctlin04 Data 19 iunie 2012 17:33:48
Problema Arbori de intervale Scor 0
Compilator fpc Status done
Runda Arhiva educationala Marime 1.32 kb
Program arbint;
 var arb:array [1..450000] of longint;
     i,n,m,op,a,b,pos,val,mid,max1:longint;
     b1,b2:array [1..1 shl 15] of char;
     fi,fo:text;
function max(a,b:longint):longint;
 begin
  if a>b then max:=a else max:=b;
 end;
procedure update(n,l,r:longint);
 begin
  if l=r then arb[n]:=val
   else begin
        mid:=(l+r) div 2;
        if pos<=mid then update(2*n,l,mid)
                     else update(2*n+1,mid+1,r);
        arb[n]:=max(arb[2*n],arb[2*n+1]);
          end;
  end;
procedure query(n,l,r:longint);
begin
 if (pos<=l) and (r<=val) then max1:=max(max1,arb[n])
  else begin
        mid:=(l+r) div 2;
        if pos<=mid then query(2*n,l,mid);
        if mid<val then query(2*n+1,mid+1,r);
        end;
end;
begin
 assign(fi,'arbint.in');
  assign(fo,'arbint.out');
 settextbuf(fi,b1); settextbuf(fo,b2);
 reset(fi); rewrite(fo); readln(fi,n,m);
  for i:=1 to n do begin
                    read(fi,op); pos:=i; val:=op;
                     update(1,1,n);
                    end;  readln(fi);
  for i:=1 to m do begin
                    readln(fi,op,a,b);
                    if op=0 then begin max1:=-1; pos:=a; val:=b; query(1,1,n); writeln(fo,max1); end
                            else begin pos:=a; val:=b; update(1,1,n); end;
                    end;
  close(fo);
end.