输入样例:
5
I 1
I 2
I 3
Q 2
Q 5
输出样例:
Yes
No
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 3;
int h[N], e[N], ne[N], idx;
void insert(int x) {
int k = (N + x % N) % N;
e[idx] = x;
ne[idx] = h[k];
h[k] = idx++;
}
bool find(int x) {
int k = (N + x % N) % N;
for (int i = h[k];i != -1;i = ne[i]) {
int j = e[i];
if (j == x) {
return true;
}
}
return false;
}
int main() {
int n;
cin >> n;
memset(h, -1, sizeof h);
while (n--) {
int x;
char op;
cin >> op;
cin >> x;
if (op == 'I') {
insert(x);
}
else {
if (find(x)) {
cout << "Yes" << endl;
}
else cout << "No" << endl;
}
}
return 0;
}