求助
查看原帖
求助
63287
Sky_Brilliant楼主2020/10/31 11:39
var now,n,tail,op,i:longint;
    x,t:int64;
    h:array[-5..1000005] of int64;
begin
    readln(n);
    tail:=0;fillchar(h,sizeof(h),0);
    for i:=1 to n do
    begin
        read(op);
        if op=1 then
        begin
            read(x);
            inc(tail);
            h[tail]:=x;
            now:=tail;
            while h[now]<h[now shr 1] do
            begin
                t:=h[now];h[now]:=h[now shr 1];h[now shr 1]:=t;
                now:=now shr 1;
                if now=1 then break;
            end;
        end;
        if op=2 then writeln(h[1]);
        if op=3 then
        begin
            h[1]:=h[tail];
            dec(tail);
            now:=1;
            while (h[now]>h[now*2]) or ((h[now]>h[now*2+1]) and (now*2+1<=tail)) do
            begin
                t:=h[now];h[now]:=h[now*2];h[now*2]:=t;
                now:=now*2;
                if now+1<=tail then
                    if h[now shr 1]>h[now+1] then
                    begin
                        t:=h[now shr 1];h[now shr 1]:=h[now+1];h[now+1]:=t;
                        now:=now+1;
                    end;
                if now*2>tail then break;
            end;
        end;
    end;
end.
2020/10/31 11:39
加载中...