@zzzc18
2017-11-09T11:46:04.000000Z
字数 773
阅读 961
模板库
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
const int MAXN = 1000000;
class Smaller_Heap{
private:
int size;
int tree[MAXN<<1];
public:
void INIT(){
memset(tree,0x7f,sizeof(tree));
}
int top(){
return tree[1];
}
void push(int x){
tree[++size]=x;
int now=size;
while(now>1){
int fa=now>>1;
if(tree[fa]>tree[now])
swap(tree[fa],tree[now]);
now>>=1;
}
}
void pop(){
int now=1;
tree[now]=tree[size--];
while((now<<1)<=size){
int lson=now<<1;int rson=now<<1|1;
int son=lson;
if(rson<=size && tree[son]>tree[rson])
son=rson;
if(tree[son]<tree[now]){
swap(tree[now],tree[son]);
now=son;
}
else
break;
}
}
}heap;
int main(){
scanf("%d",&n);
heap.INIT();
for(int i=1;i<=n;i++){
int opt,x;
scanf("%d",&opt);
if(opt==1){
scanf("%d",&x);
heap.push(x);
}
else if(opt==2){
printf("%d\n",heap.top());
}
else
heap.pop();
}
return 0;
}