MEX

#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 10;

struct mex_tool {
    set<int> st;
    int cot[N];

    void init() {
        for(int i = 0; i < N; ++i) st.insert(i);
    }

    void insertt(int x){
        if(cot[x] == 0) st.erase(x);
        cot[x]++;
    }

    int query(){
        return *st.begin();
    }

    void deletee(int x){
        if(cot[x] == 1){
            st.insert(x);
        }
        cot[x]--;
    }
}mex;

int m, op, x;

signed main(){
    mex.init();

    cin >> m;
    while(m--){
        cin >> op;
        if(op == 0){
            cin >> x;
            mex.insertt(x); //插入一个数
        }else if(op == 1){
            cout << mex.query() << "\n"; //查询MEX
        }else{
            cin >> x;
            mex.deletee(x); //删除一个数
        }
    }
    return 0;
}

 

posted @ 2022-04-19 19:02  std&ice  阅读(296)  评论(0编辑  收藏  举报