Cod sursa(job #360866)

Utilizator philipPhilip philip Data 2 noiembrie 2009 14:57:36
Problema Arbori de intervale Scor 100
Compilator fpc Status done
Runda Arhiva educationala Marime 1.72 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 shl 1]>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);
  assign(output,'arbint.out');
  rewrite(output);
  readln(n,m);{
  k:=1;
  read(s);
  for x:=1 to n do begin
    y:=0;
    while (s[k]<>' ') do begin
      y:=y*10+ord(s[k])-48;
      k:=k+1;
      if (k=length(s)+1) then begin
        read(s);
        k:=1;
      end;
    end;
    k:=k+1;
    inlocuieste(1,1,n);
  end;         }
  y:=0;
  x:=0;
  while (not(eoln(input))) do begin
    read(s);
    for k:=1 to length(s) do begin
      if s[k]=' ' then begin
        x:=x+1;
        inlocuieste(1,1,n);
        y:=0;
      end else y:=y*10+(ord(s[k])-48);
    end;
  end;
  if s[k]<>' ' then inlocuieste(1,1,n);



  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.