WA44求调
查看原帖
WA44求调
658762
sxq9楼主2024/3/15 21:22

rt

#include<bits/stdc++.h>
#define lson i*2
#define rson i*2+1
#define father i/2
using namespace std;
int tree[1000010];
int main(){
	int n,cnt=0;
	cin>>n;
	for(int t=1;t<=n;t++){
		int cao,num,i;
		cin>>cao;
		if(cao==1){
			cin>>num;
			tree[++cnt]=num;
			i=cnt;
			while(tree[father]>tree[i])swap(tree[father],tree[i]),i=father;
		}
		else if(cao==2)cout<<tree[1]<<endl;
		else{
			swap(tree[1],tree[cnt]);
			cnt--;
			i=1;
			while(tree[i]>tree[lson]&&lson<=cnt||tree[i]>tree[rson]&&rson<=cnt){
				if(tree[i]>tree[lson])swap(tree[i],tree[lson]),i=lson;
				else swap(tree[i],tree[rson]),i=rson;
			}
		}
	} 
	return 0;
}

2024/3/15 21:22
加载中...