题解 | 两端问优先队列
两端问优先队列
https://www.nowcoder.com/practice/da2887a3fd8549ad826c9cbdaa67f513
#include<bits/stdc++.h>
using namespace std;
int n,op,x;
multiset<int> mst;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n;
while(n--){
cin>>op;
if(op==1){
cin>>x;
mst.insert(x);
}else if(op==2){
cout<<*mst.begin()<<endl;
}else if(op==3){
cout<<*(--mst.end())<<endl;
}else if(op==4){
mst.erase(mst.begin());
}else if(op==5){
mst.erase(--mst.end());
}
}
return 0;
}
文远知行公司福利 588人发布
