writeln(max);
end.
7. 线段树
type
node=record
p,r,m:longint; //[p,r) m = (p+r) div 2
k:longint;
left,right:longint;
end;
var
a:array[0..1000000] of node;
data:array[0..1000000] of longint;
i,j,n,m,tot,x,y,p,c:longint;
function min(a,b:longint):longint;
begin
if a>b then exit(b) else exit(a);
end;
procedure buildtree(t:longint);
begin
if a[t].p+1=a[t].r then
begin
a[t].k:=data[a[t].p];
exit;
end;
a[t].m:=(a[t].p+a[t].r) div 2;
//left
inc(tot);
a[t].left:=tot;
a[tot].p:=a[t].p;
a[tot].r:=a[t].m;
buildtree(tot);
//right
inc(tot);
a[t].right:=tot;