type my=recordval,l,r:longint;end;var n,i,root,a,ppool:longint;da:array[0..100010]of my;procedure print(v:longint);beginif v=0 then exit;print(da[v].l);write(da[v].val,' ');print(da[v].r);end;procedure ins(var v:longint;a:longint);beginif v=0 thenbegininc(ppool);v:=ppool;da[v].val:=a;end;if a

问题描述:

type my=record
val,l,r:longint;
end;
var n,i,root,a,ppool:longint;
da:array[0..100010]of my;
procedure print(v:longint);
begin
if v=0 then exit;
print(da[v].l);
write(da[v].val,' ');
print(da[v].r);
end;
procedure ins(var v:longint;a:longint);
begin
if v=0 then
begin
inc(ppool);
v:=ppool;
da[v].val:=a;
end;
if a

请等一下 我在看你的程序.
我也搞过OI
能补充一下问题是什么吗.
我的机子上没有FP
要帮您调试的话稍等下
经过我简单的调试
发现ins过程中少了一的exit导致201暴栈
如果没有其他错误因该是
在da[v].val:=a;后加一个exit;
我本人写c++的 pascal可能写不好.
正确程序:
type my=record
val,l,r:longint;
end;
var n,i,root,a,ppool:longint;
da:array[0..100010]of my;
procedure print(v:longint);
begin
if v=0 then exit;
print(da[v].l);
write(da[v].val,' ');
print(da[v].r);
end;
procedure ins(var v:longint;a:longint);
begin
if v=0 then
begin
inc(ppool);
v:=ppool;
da[v].val:=a;
exit;
end;
if ab then exit(b) else exit(a);
end;
function max(a,b:longint):longint;
begin
if a>b then exit(a) else exit(b);
end;
constructor Ttreap.init;
begin
randomize;
total:=1;
with t[total] do
begin
total:=1;
key:=-1;
value:=-1;
fa:=0;
end;
root:=1;
end;
procedure Ttreap.turn(father,son:longint);
begin
t[son].fa:=t[father].fa;
if t[t[father].fa].right=father then t[t[father].fa].right:=son
else t[t[father].fa].left:=son;
t[father].fa:=son;
if t[father].right=son then
begin
t[t[son].left].fa:=father;
t[father].right:=t[son].left;
t[son].left:=father;
end
else
begin
t[t[son].right].fa:=father;
t[father].left:=t[son].right;
t[son].right:=father;
end;
t[son].total:=t[father].total;
t[father].total:=t[t[father].left].total+t[t[father].right].total+1;
end;
procedure Ttreap.insert(x:longint);
var
i,last:longint;
begin
i:=root;
while i0 do
begin
last:=i;
inc(t[i].total);
if x>t[i].value then i:=t[i].right
else i:=t[i].left;
end;
inc(total);
with t[total] do
begin
total:=1;
key:=random(range);
value:=x;
left:=0;
right:=0;
fa:=last;
end;
if x>t[last].value then t[last].right:=total else t[last].left:=total;
while t[total].keyt[i].value then i:=t[i].right
else
begin
h:=i;
i:=t[i].left;
end;
end;
t[h].value:=t[last].value;
t[h].key:=t[last].key;
if t[last].left=0 then k:=t[last].right else k:=t[last].left;
j:=t[last].fa;
t[k].fa:=j;
if t[j].left=last then t[j].left:=k else t[j].right:=k;
end;
function Ttreap.find(x:longint):longint;
var
i:longint;
begin
i:=t[root].right;
while x>0 do
begin
if t[t[i].left].total+1=x then exit(t[i].value);
if t[t[i].left].total>=x then i:=t[i].left
else
begin
x:=x-t[t[i].left].total-1;
i:=t[i].right;
end;
end;
end;
procedure qsort(left,right:longint);
var
i,j,x,xx:longint;
begin
i:=left;
j:=right;
x:=a[(i+j) shr 1];
xx:=b[(i+j) shr 1];
while i