题解 | 两端问优先队列

两端问优先队列

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;
}


全部评论

相关推荐

烤点老白薯:亲娘嘞🐶💩啊你的简历
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务