思路
-
对于1,2两个操作可以用队列q,简单的模拟即可,关键是第3个排序操作。 我们可以这样,开一个优先队列pq,对于插入操作,直接插入q
-
对于排序操作,我们将q中的元素全部插入到pq中,我们可以肯定的是对于每 一次排序操作,这些数字肯定在后来插入的数之前(未进行下一次排序操作的时候是),前面有序,后面无序,所以对于操作2,如果优先队列里面有元素,那么输出弹出优先队列对头,否则弹出普通队列队头。
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+9;
set<int> a;
int q[N*10];
priority_queue<int,vector<int> ,greater<int> > pq;
int main()
{
int hh=0,tt=-1;
int Q;
cin>>Q;
while(Q--)
{
int op;
scanf("%d",&op);
if(op==1)
{
int x;
scanf("%d",&x);
q[++tt]=x;
}
else if(op==2)
{
if(pq.size())
{
printf("%d\n",pq.top());
pq.pop();
}
else printf("%d\n",q[hh++]);
}
else
{
while(hh<=tt)
{
pq.push(q[hh++]);
}
}
}
return 0;
}