这题可以用队列和动态数组
看了一下其他人的题解,发现都用的是我看不懂的二叉树,所以写个没人要的队列
思路:
根据题意,删除或输出或加入队列,直接模拟
在 a 等于1的时候将 b 插入队列
在 a 等于2的时候且队列不为空的时候输出队列的最小值
在 a 等于3的时候删除最小值
代码:
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int main()
{
int n;
cin >> n;
priority_queue<int, vector<int>, greater<int>> c;
for (int i = 0; i < n; i++)
{
int a, b;
cin >> a;
if (a == 1)
{
cin >> b;
c.push(b);//将b加入队列末尾
}
else if (a == 2)
{
if (!c.empty())
{
cout << c.top() << endl;//在不为空的时候输出最小值也就是最后一个
}
}
else
{
if (!c.empty())
{
c.pop();//删除最后的的最小值
}
}
}
return 0;
}