12pts求助(求调),悬赏关注一个
查看原帖
12pts求助(求调),悬赏关注一个
559506
RJSPZ楼主2022/12/1 13:42
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
namespace io {
    inline ull read() {
        char ch = getchar(); ull flag = 1, ans = 0;
        while (ch < '0' || ch > '9') { if (ch == '-') flag = -1; ch = getchar(); }
        while (ch >= '0' && ch <= '9') ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
        return flag * ans;
    }
    inline void write(int x) {
        if (x < 0) putchar('-'), x = -x;
        if (x > 9) write(x / 10);
        putchar(x % 10 + '0');
    }
}
using namespace io;
const int N=1e6+7;
ull n,op,s;
ull h[N];
inline void down(int u){
    int t=u;
    if((u<<1)<=s&&h[u<<1]<h[t]){
        t=(u<<1);
    }
    if((u<<1)+1<=s&&h[(u<<1)+1]<h[t]){
        t=(u<<1)+1;
    }
    if(u!=t){
        swap(h[u],h[t]);
        down(t);
    }
    return ;
}
int main(){
	n=read();
	while(n--){
		op=read();
		if(op==1){
			h[s]=read();
			s++;
			down(1);
		}
		else if(op==2){
			write(h[1]),puts("");
		}
		else{
			h[1]=h[s];
			s--;
			down(1);
		}
	}
	return 0;
}
2022/12/1 13:42
加载中...