Pagini recente » Cod sursa (job #767533) | Cod sursa (job #2021414) | Cod sursa (job #3253406) | Cod sursa (job #1444638) | Cod sursa (job #562425)
Cod sursa(job #562425)
var t:array[1..1 shl 18] of longword;
m,maxim,p,v,a,b:longword;
function max(a,b:longword):longword;
begin
if a>b then max:=a else max:=b;
end;
procedure update(nod,l,r:longword);
begin
if l<r then
if p<=(l+r) shr 1 then
update(nod shl 1,l,(l+r) shr 1)
else
update((nod shl 1)+1,((l+r) shr 1)+1,r);
if l=r then
t[nod]:=v else t[nod]:=max(t[nod shl 1],t[(nod shl 1)+1]);
end;
procedure query(nod,l,r:longword);
begin
if (a<=l) and (r<=b) then
begin
if maxim<t[nod] then maxim:=t[nod];
exit
end
else
begin
if a<=(l+r) shr 1 then query(nod shl 1,l,(l+r) shr 1);
if (l+r) shr 1<b then query((nod shl 1)+1,((l+r) shr 1)+1,r);
end;
end;
procedure citire;
var n,m,i:longword;
x,y,z:longword;
begin
assign(input,'arbint.in');reset(input);
readln(n,m);
for i:=1 to n do
begin
read(x);
p:=i;v:=x;
update(1,1,n);
end;
assign(output,'arbint.out');rewrite(output);
for i:=1 to m do
begin
readln(x,y,z);
if x=0 then
begin
a:=y;
b:=z;maxim:=0;
query(1,1,n);
writeln(maxim);
end
else
begin
p:=y;
v:=z;
update(1,1,n);
end;
end;
close(input);close(output);
end;
begin
citire;
end.