散列表-拉链法/开放寻址法(这是拉链)
#include<iostream>
#include<cstring>
using namespace std;
const int N = 100013;
int h[N], ne[N], e[N];
int idx = 0;
int n, x;
char opt;
void insert(int x) {
int k = (x % N + N) % N;
e[idx] = x;
ne[idx] = h[k];
h[k] = idx ++ ;
}
bool find(int x) {
int k = (x % N + N) % N;
for (int i = h[k]; i != -1; i = ne[i]) {
if (x == e[i]) return true;
}
return false;
}
int main() {
cin >> n;
memset(h, -1, sizeof h);
while (n -- ) {
cin >> opt;
if (opt == 'I') {
cin >> x;
insert(x);
}
else if (opt == 'Q') {
cin >> x;
if (find(x)) cout << "Yes" << endl;
else cout << "No" << endl;
}
}
}