multiset

#include<bits/stdc++.h>
#define int long long 
#define pb push_back
#define fi first
#define se second 
#define bg begin()
#define ed end()
#define rbg rbegin()
#define all(x) x.bg,x.ed
#define cy cout<<"YES"<<endl
#define cn cout<<"NO"<<endl
#define de(x) cout<<x<<"###"<<endl
using namespace std;
const long long inf=2e18;
typedef long long ll;
typedef pair<ll,ll>pii;
typedef vector<ll>vi;
const double eps=1e-8;
const int mod=1e9+7;
const int N=2e5+5;
void solve(){
    int q;
    cin>>q;
    multiset<int>st;
    while(q--){
        int op;
        cin>>op;
        if(op==1){
            int x;
            cin>>x;
            st.insert(x);
        }
        else if(op==2){
            int x,c;
            cin>>x>>c;
            while(c--&&st.find(x)!=st.ed){
                st.erase(st.find(x));
            }
        }
        else cout<<*st.rbg-*st.bg<<endl;
    }
}        
signed main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif 
    ios::sync_with_stdio(false);
      cin.tie(0);
//    int t;
//    cin>>t;
//    while(t--){
        solve();
//    }
    return 0;
}

删除单个元素x:st.erase(st.find(x));

删除所有x:st.erase(x);

最大值:*st.rbegin()

最小值:*st.begin()

posted @ 2022-08-19 16:10  Candyk8d9  阅读(36)  评论(0)    收藏  举报