指纹锁(牛客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;
}

浙公网安备 33010602011771号