#851. 模拟散列表

模拟散列表

输入样例

5
I 1
I 2
I 3
Q 2
Q 5

输出样例

Yes
No
开放寻址法
#include<bits/stdc++.h>
using namespace std;

const int N = 2e5+3;
int n, a[N];
int mfind(int x){
	//找x应该存放的位置
	int t = (x%N + N) % N;
	while(a[t]!=0x3f3f3f3f && a[t]!=x) t = (t+1) % N;
	return t;
}
int main(){
	memset(a, 0x3f, sizeof a);
	cin >> n;
	while(n--){
		char c;
		int x;
		cin >> c >> x;
		if(c == 'I') a[mfind(x)] = x; 
		else if(a[mfind(x)] != x) cout << "No\n";
		else cout << "Yes\n";
	}
	return 0;
}