#C. 模拟散列表

    传统题 1000ms 256MiB

模拟散列表

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

输入样例

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;
}

【L2-第39课】-trip和哈希.2025.04.12

未认领
状态
已结束
题目
3
开始时间
2025-4-12 0:00
截止时间
2025-4-20 23:59
可延期
24 小时