思路(saber 专用)
这道题是标准的 hash,但是 C ++ 中有基于hash 实现的 unordered_set 和 unordered_map。于是乎,我们就可以利用这些好东西来实现该题。
C++ 代码
#include <bits/stdc++.h>
using namespace std;
int main(){
unordered_set<int> s;
int n;
cin >> n;
while ( n -- ){
char ch;
int x;
cin >> ch >> x;
if (ch == 'I') s.insert(x);
else{
if (s.find(x) != s.end()) puts("Yes");
else puts("No");
}
}
return 0;
}