28分,求助大佬!!!
查看原帖
28分,求助大佬!!!
677514
Frodo楼主2022/7/20 15:37

Code:

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1000001;
int n,len=0,op,xx,a[N];
int read() {
	int ret=0;
	char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') {
		ret=ret*10+(ch-48);
		ch=getchar();
	}
	return ret;
}
void put_in(int x) {
	len++;
	int i=len;
	a[i]=x;
	while(i!=1&&a[i/2]>a[i]) {
		swap(a[i/2],a[i]);
		i=i/2;
	}
}
int put_out() {
	int i=1,j,tmp=a[1];
	a[1]=a[len];
	len--;
	while(2*i<=len) {
		if(2*i+1>len||a[2*i]<a[2*i+1]) j=2*i;
		if(a[i]>a[j]) {
			swap(a[i],a[j]);
			i=j;
		} else return tmp;
	}
	return tmp;
}
int main() {
	n=read();
	for(int i=1; i<=n; i++) {
		op=read();
		if(op==1) {
			xx=read();
			put_in(xx);
		}
		if(op==2) cout<<a[1]<<endl;
		if(op==3) put_out();
	}
	return 0;
}
2022/7/20 15:37
加载中...