AcWing 840. 模拟散列表
原题链接
简单
作者:
墨白
,
2021-02-23 09:33:47
,
所有人可见
,
阅读 237
题目描述
C++ 代码
#include <iostream>
#include <cstring>
using namespace std;
const int N = 200003 , null = 0x3f3f3f3f;
int h[N];
int find(int x){
int t = (x % N + N) % N;
while(h[t] != null && h[t] != x){
t++;
if(t == N) t = 0;
}
return t;
}
int main(){
int n;
cin >> n;
memset(h, 0x3f , sizeof h);
while(n--){
char c;
int x;
cin >> c >> x;
if(c == 'I'){
h[find(x)] = x;
}else{
if(h[find(x)] == null) cout << "No" << endl;
else cout << "Yes" << endl;
}
}
return 0;
}