Cod sursa(job #360859)

Utilizator philipPhilip philip Data 2 noiembrie 2009 14:12:43
Problema Arbori de intervale Scor 50
Compilator fpc Status done
Runda Arhiva educationala Marime 1.22 kb
var a:array[1..264000] of longint;
    n,m,i,op,x,y,maxim,k:longint;
    s:string;


procedure inlocuieste(nod,st,dr:longint);
  var mij:longint;
  begin
    if st>=dr then begin a[nod]:=y; exit; end
      else begin
        mij:=(st+dr)shr 1;
        if x<=mij then
          inlocuieste((nod shl 1),st,mij) else
            inlocuieste((nod shl 1)+1,mij+1,dr);
        if a[nod*2]>a[(nod shl 1)+1] then
          a[nod]:=a[(nod shl 1)] else
            a[nod]:=a[(nod shl 1)+1];
      end;
  end;

procedure max(nod,st,dr:longint);
  var mij:longint;
  begin
    if (x<=st) and (y>=dr) then begin
      if maxim<a[nod] then  maxim:=a[nod]; exit;  end
    else begin
      mij:=(st+dr) shr 1;
      if x<=mij then max(nod shl 1,st,mij);
      if y>mij then max((nod shl 1)+1,mij+1,dr);
    end;
  end;

begin
  assign(input,'arbint.in');
  reset(input);
  readln(n,m);
  for x:=1 to n do begin
    read(y);
    inlocuieste(1,1,n);
  end;


  assign(output,'arbint.out');
  rewrite(output);


  for i:=1 to m do begin
    read(op,x,y);
    if op=1 then begin
      inlocuieste(1,1,n);
    end else begin
      maxim:=0;
      max(1,1,n);
      writeln(maxim);
    end;
  end;
  close(output);
end.