(洛谷 3378)堆

来源:互联网 发布:云南交通投资公司知乎 编辑:程序博客网 时间:2024/06/14 11:41

操作1: 1 x 表示将x插入到堆中

操作2: 2 输出该小根堆内的最小数

操作3: 3 删除该小根堆内的最小数

分析:运用了堆的思想。对于蒟蒻来说优先队列真是个好东西。

#include <cstdio>
#include <queue>
using namespace std;
priority_queue<int>q;
int n;
int main(){
scanf("%d",&n);
while (n--){
int x,y;
scanf("%d",&x);
if (x==1){
scanf("%d",&y);
q.push(-y);//插入变成小根堆
}
else if (x==2) printf("%d",-q.top());//当然要恢复原样
else q.pop();//弹出
}
}



原创粉丝点击