题解 | 两端问优先队列 | multiset实现

两端问优先队列

https://www.nowcoder.com/practice/da2887a3fd8549ad826c9cbdaa67f513

#include <iostream>
#include <set>
using namespace std;

void op1(multiset<int>& mst){
    int x;cin>>x;
    mst.insert(x);
}

void op2(const multiset<int>& mst){
    cout<<*mst.begin()<<'\n';
}

void op3(const multiset<int>& mst){
    cout<<*mst.rbegin()<<'\n';
}

void op4(multiset<int>& mst){
    if(!mst.empty()) mst.erase(mst.begin());
}

void op5(multiset<int>& mst){
    if(!mst.empty()) mst.erase(prev(mst.end()));
}


int main(){
    ios::sync_with_stdio(false);cin.tie(nullptr);
    multiset<int> mst;
    int tests;cin>>tests;
    while(tests--){
        int op;cin>>op;
        switch(op){
            case 1:op1(mst);break;
            case 2:op2(mst);break;
            case 3:op3(mst);break;
            case 4:op4(mst);break;
            case 5:op5(mst);break;
            default:;
        }
    }

    return 0;
}

全部评论

相关推荐

牛客62533758...:华为不卡双非,而是卡院校hhhh
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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