Pagini recente » Cod sursa (job #1139516) | Cod sursa (job #1372762) | Cod sursa (job #873153) | Cod sursa (job #1778214) | Cod sursa (job #152191)
Cod sursa(job #152191)
var arbo:array[1..300001] of longint;
n,i,j,k,m,x,a,b,goi,gof,poz,max:longint;
function maxim(x,y:longint):longint;inline;
begin
if x>y then maxim:=x
else maxim:=y;
end;
procedure update(ni,st,dr:longint);
var mij:longint;
begin
if st=dr then
begin
arbo[ni]:=x;
end
else
begin
mij:=(st+dr) div 2;
if poz<=mij then update(2*ni,st,mij)
else update(2*ni+1,mij+1,dr);
arbo[ni]:=maxim(arbo[2*ni],arbo[2*ni+1]);
end;
end;
procedure caut(ni,st,dr:longint);
var mij:longint;
begin
if (goi<=st)and(dr<=gof) then
if max<arbo[ni] then max:=arbo[ni]
else
else
begin
mij:=(st+dr) div 2;
if (goi<=mij) then caut(2*ni,st,mij);
if (mij<gof) then caut(2*ni+1,mij+1,dr);
end;
end;
begin
assign(input,'arbint.in');
assign(output,'arbint.out');
reset(input);
rewrite(output);
readln(N,m);
for i:=1 to n do
begin
read(X);
poz:=i;
update(1,1,n);
end;
for i:=1 to m do
begin
readln(x,a,b);
if x=0 then
begin
max:=0;
goi:=a;
gof:=b;
caut(1,1,N);
writeln(max);
end
else
begin
poz:=a;
x:=b;
update(1,1,N);
end;
end;
close(input);
close(output);
end.