#include<iostream> #include<cstring> #include<algorithm> using namespace std; const int N = 10003; int h[N], e[N], ne[N],idx; 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 (e[i] == x)return true; } return false; } int main() { memset(h, -1, sizeof(h)); string a; int n,x; cin >> n; while (n--) { cin >> a >> x; if (a == "I") { Insert(x); } else { if (find(x)) { cout << "Yes"; } else cout << "No"; } } return 0; }
算法.哈希表.拉链法
最新推荐文章于 2024-09-12 19:02:20 发布