链接:https://www.nowcoder.com/acm/contest/136/G
来源:牛客网
第一行有2个正整数m,k。
接下来m行,每行描述一种操作:add x,del x或query x。
对于每个query操作,输出一行,包含一个单词“Yes”或“No”,表示该人是否可以打开指纹锁。
对于100%的测试数据:
1 ≤ k,m ≤ 1000000
数据量较大,注意使用更快的输入输出方式。
分析:赛后看别人的代码,get到了新知识点,set可以自动定义排序还可以定义是否可以插入。。
AC代码:
#include <map> #include <set> #include <stack> #include <cmath> #include <queue> #include <cstdio> #include <vector> #include <string> #include <bitset> #include <cstring> #include <iomanip> #include <iostream> #include <algorithm> #define ls (r<<1) #define rs (r<<1|1) #define debug(a) cout << #a << " " << a << endl using namespace std; typedef long long ll; const ll maxn = 1e6+10; const double eps = 1e-8; const ll mod = 1e9 + 7; const int inf = 0x3f3f3f3f; const double pi = acos(-1.0); ll m, k; struct cmp { //自定义排序规则,差值小于k的加不进集合 bool operator() ( ll a, ll b ) { if( abs(a-b) <= k ) { return false; } return a < b; } }; int main() { ios::sync_with_stdio(0); cin >> m >> k; set<ll,cmp> s; while( m -- ) { string str; ll x; cin >> str >> x; if( str[0] == ‘a‘ ) { if( s.find(x) == s.end() ) { s.insert(x); } } else if( str[0] == ‘d‘ ) { s.erase(x); } else { if( s.find(x) != s.end() ) { cout << "Yes" << endl; } else { cout << "No" << endl; } } } return 0; }
原文:https://www.cnblogs.com/l609929321/p/9525880.html