飞机票票
题目描述
给定一个数列,初始为空,请支持下面三种操作:
- 给定一个整数 xx,请将 xx 加入到数列中。
- 输出数列中最小的数。
- 删除数列中最小的数(如果有多个数最小,只删除 11 个)。
输入格式
第一行是一个整数,表示操作的次数 nn。
接下来 nn 行,每行表示一次操作。每行首先有一个整数 opop 表示操作类型。
- 若 op = 1op=1,则后面有一个整数 xx,表示要将 xx 加入数列。
- 若 op = 2op=2,则表示要求输出数列中的最小数。
- 若 op = 3op=3,则表示删除数列中的最小数。如果有多个数最小,只删除 11 个。
输出格式
对于每个操作 22,输出一行一个整数表示答案。
思路:
优先队列模拟即可。
#include<bits/stdc++.h>
#define bug(a) cout<<"bug1 : "<<a<<endl;
#define bugg(a,b) cout<<"bug2 : "<<a<<" "<<b<<endl;
using namespace std;
#define endl '\n'
//#define int long long
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int main()
{
priority_queue<int,vector<int>,greater<int> >mo;
int n,i,j,t;
cin>>n;
for(i=0;i<n;i++)
{
cin>>t;
if(t==1)
{
cin>>j;
mo.push(j);
}
else if(t==2)
{
cout<<mo.top()<<endl;
}
else
{
mo.pop();
}
}
return 0;
}