Cod sursa(job #360123)

Utilizator philipPhilip philip Data 29 octombrie 2009 22:23:30
Problema Arbori de intervale Scor 50
Compilator fpc Status done
Runda Arhiva educationala Marime 1.52 kb
var f,g:text;
    a:array[1..262143] of longint;
    n,m,i,op,x,y,maxim:longint;

procedure introduce(nod,st,dr:longint);
  var mij:longint;
  begin
    if st>=dr then read(f,a[nod])
      else begin
        mij:=trunc((st+dr)/2);
        introduce(nod*2,st,mij);
        introduce(nod*2+1,mij+1,dr);
        if a[nod*2]>a[nod*2+1] then
          a[nod]:=a[nod*2] else
            a[nod]:=a[nod*2+1];
      end;
  end;

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

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

begin
  assign(f,'arbint.in');
  reset(f);
  readln(f,n,m);
  introduce(1,1,n);


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


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

for x:=1 to n*2-1 do write(g,a[x],' ');
      writeln(g);