AT_abc217_e Sorting Queries 题解
这道题我们只需要创建一个优先队列和一个普通队列即可。
对于
对于
而对于
具体见代码
#include<bits/stdc++.h>
using namespace std;
int Q,x,opt;
priority_queue<int,vector<int>,greator<int> > qu;//越小越优先的优先队列
queue<int> q;//普通队列
int main(){
cin>>Q;
while(Q--){
cin>>opt;
if(opt==1){//1操作
cin>>x;
q.push(x);
}
else if(opt==2){//2操作
if(qu.size()){
cout<<qu.top()<<endl;
qu.pop();
}
else{
cout<<q.front()<<endl;
q.pop();
}
}
else{//3操作
while(q.size()){
qu.push(q.front());//将普通队列中的数转移到优先队列中
q.pop();
}
}
}
return 0;
}