36分,求助,必关!!
查看原帖
36分,求助,必关!!
1300671
Halen1happy楼主2024/12/19 19:46
#include<bits/stdc++.h>
using namespace std;
int h[1000005];
int cnt=0;
void down(int u){
	int t=u;
	if(u*2+1<=cnt&&h[u*2+1]<h[t]) t=u*2+1;
	if(u*2<=cnt&&h[u*2]<h[t]) t=u*2;
	if(u!=t){
		swap(h[u],h[t]);
		down(t);
	}
}
int main(){
	int n,m;
	cin>>n;
	for(int i=n/2;i;i--) down(i);
	while(n--){
		char op;
		cin>>op;
		if(op=='1'){
			int x;
			cin>>x;
			h[++cnt]=x;
		}else if(op=='2'){
			down(1);
			if(h[cnt]!=0){
				cout<<h[1]<<endl;
			}else{
				cout<<0<<endl;
			}
			
		}else if(op=='3'){
			down(1);
			h[1]=h[cnt];
			cnt--;
		
		}
	}
	return 0;
}
2024/12/19 19:46
加载中...