Pagini recente » Cod sursa (job #3140570) | Cod sursa (job #3244561) | Cod sursa (job #2767986) | Cod sursa (job #2954970) | Cod sursa (job #599968)
Cod sursa(job #599968)
const fin = 'arbint.in'; fout = 'arbint.out';
type arborele = array[1..100000] of longword;
buffer = array[1..1 shl 17] of char;
var arb : arborele;
bufin, bufout : buffer;
n ,x ,y ,r : longword;
function max( a ,b : longword ) : longword;
begin
if (a > b) then max := a else max := b;
end;
procedure construieste( nod ,st ,dr : longword );
var mij : longword;
begin
if (st = dr) then read( arb[nod] ) else
begin
mij := (st + dr) div 2;
construieste( 2 * nod ,st ,mij );
construieste( 2 * nod + 1, mij + 1, dr);
arb[nod] := max( arb[2 * nod], arb[2 * nod + 1] );
end;
end;
procedure reface( nod ,st ,dr : longword );
var mij : longword;
begin
if (st = dr) then arb[nod] := y else
begin
mij := (st + dr) div 2;
if (x <= mij) then reface( 2 * nod ,st ,mij ) else
reface( 2 * nod + 1, mij + 1, dr );
arb[nod] := max( arb[2 * nod] ,arb[2 * nod + 1] );
end;
end;
procedure interogheaza( nod ,st ,dr : longword );
var mij : longword;
begin
if (x <= st) and (dr <= y) then
begin
if (r < arb[nod]) then r := arb[nod];
exit();
end;
mij := (st + dr) div 2;
if (x <= mij) then interogheaza( 2 * nod, st, mij );
if (mij < y) then interogheaza( 2 * nod + 1, mij + 1, dr );
end;
procedure main();
var
m ,i : longword;
op : byte;
begin
assign( input , fin ); reset( input );
assign( output , fout ); rewrite( output );
settextbuf( input , bufin );
settextbuf( output , bufout );
readln( n ,m );
construieste( 1, 1, n );
for i := 1 to m do
begin
readln( op, x, y );
if (op = 1) then reface( 1, 1, n ) else
begin
r := 0;
interogheaza( 1, 1, n );
write( r, #10 );
end;
end;
end;
begin
main();
end.