原题链接:https://www.luogu.com.cn/problem/P3378
目录
1. 题目描述
2. 思路分析
3. 代码实现
1. 题目描述

2. 思路分析
一道模板题,主要是熟悉STL中优先队列(priority_queue)的使用。
堆的STL实现:
priority_queue<int> q; //这是一个大根堆q(默认为大根堆)
priority_queue<int,vector<int>,greater<int> >q; //这是一个小根堆q
优先队列的操作:
q.top();    //取得堆顶元素,并不会弹出
 q.pop();    //弹出堆顶元素
 q.push();    //往堆里面插入一个元素
 q.empty();    //查询堆是否为空,为空则返回1,否则返回0
 q.size();    //查询堆内元素数量
3. 代码实现
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
	int n; cin >> n;
	priority_queue <ll, vector<ll>, greater<ll>>pq;
	while (n--) {
		int op; cin >> op;
		if (op == 1) {
			int x; cin >> x;
			pq.push(x);
		}
		else if (op == 2) {
			cout << pq.top() << '\n';
		}
		else {
			pq.pop();
		}
	}
}
int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	solve();
	return 0;
}
 


















