看了大佬题解,学到了
Code
#include <bits/stdc++.h>
using namespace std;
int m,k,x;
char s[10];
struct cmp{
bool operator () (const int & x,const int & y) const {
if(abs(x-y)<=k) return false;
return x < y;
}
};
set<int,cmp> se;
int main(){
scanf("%d %d",&m,&k);
while(m--){
scanf("%s",s);scanf("%d",&x);
if(s[0]=='a') se.insert(x);
else if(s[0]=='d') se.erase(x);
else{
if (se.find(x)!=se.end()) puts("Yes");
else puts("No");
}
}
return 0;
}
京公网安备 11010502036488号