指纹锁(牛客STL)

指纹锁

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

typedef long long ll;

ll m, k;

struct cmp{
    bool operator()(ll a, ll b)const{
        if(abs(a - b) <= k) return 0;
        return a < b;
    }
};

signed main(){
    ios::sync_with_stdio(false); cin.tie(0), cout.tie(0);
    cin >> m >> k;
    set<ll, cmp> st;
    for(int i = 0; i < m; ++i){
        string s; ll x; cin >> s >> x;
        if(s == "add") st.insert(x);
        else if(s == "del") st.erase(x);
        else{
            if(st.count(x)) cout << "Yes" << endl;
            else cout << "No" << endl;
        }
    }
    return 0;
}
posted @ 2025-03-19 13:21  awei040519  阅读(12)  评论(0)    收藏  举报