AcWing 840. 模拟散列表
原题链接
简单
作者:
zct
,
2024-12-13 13:17:47
,
所有人可见
,
阅读 1
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
const int N = 100003;
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()
{
int n;
cin >> n;
memset(h, -1, sizeof h);
while (n -- )
{
char op[2];
int x;
cin >> op >> x;
if (*op == 'I') insert(x);
else
{
if (find(x)) cout << "Yes" << endl;
else cout << "No" << endl;
}
}
return 0;
}