Cod sursa(job #1420342)

Utilizator ButnaruButnaru George Butnaru Data 18 aprilie 2015 12:26:48
Problema Arbori de intervale Scor 100
Compilator fpc Status done
Runda Arhiva educationala Marime 1.11 kb
program arbint; uses math;
type vector1=array[0..400001] of longint;
var arb:vector1;
    n,m,tip,x,y,i:longint;
    f1,f2:text;
procedure build(nod,st,dr:longint);
var m:longint;
begin
if st=dr then read (f1,arb[nod]) else begin
m:=(st+dr) div 2;
build(nod*2,st,m);
build(nod*2+1,m+1,dr);
arb[nod]:=max(arb[nod*2],arb[nod*2+1]);
end;
end;
procedure update(nod,st,dr:longint);
var m:longint;
begin
if (st=dr) then arb[nod]:=y else begin
m:=(st+dr) div 2;
if x<=m then update(nod*2,st,m) else
update(nod*2+1,m+1,dr);
arb[nod]:=max(arb[nod*2],arb[nod*2+1]);
end;
end;
function query(nod,st,dr:longint):longint;
var m,maxx:longint;
begin
if (st>=x) and (dr<=y) then exit(arb[nod]) else begin
m:=(st+dr) div 2; maxx:=0;
if x<=m then maxx:=max(maxx,query(nod*2,st,m));
if y>m then maxx:=max(maxx,query(nod*2+1,m+1,dr));
query:=maxx;
end;
end;
begin
assign (f1,'arbint.in');
assign (f2,'arbint.out');
reset (f1);
rewrite (f2);
readln (f1,n,m);
build(1,1,n);
for i:=1 to m do begin
readln (f1,tip,x,y);
if tip=0 then writeln (f2,query(1,1,n)) else
update(1,1,n);
end;
close (f1);
close (f2);
end.