哈希表的模数
查看原帖
哈希表的模数
228738
widsnoy楼主2020/7/30 18:32

哈希表模数设置为19260817就会TLE四个点。而改小就能AC?

namespace H {
	const int M = 19260817;
	int hd[M] = {}, tot = 0;
	struct E{int nxt, o; ll v;}e[N];
	void clear() {memset(hd, 0, sizeof(hd));tot = 0;}
	void ins(int h, int o) {int t = ((h % M + M) % M + M) % M, mx = max(t, mx); e[++tot] = E{hd[t], o, h}; hd[t] = tot;}
	int query(int h) {for(int i = hd[((h % M + M) % M + M) % M]; i; i = e[i].nxt) if(e[i].v == h) return e[i].o; return -1;}
}

理论来说不是大质数更快吗?有没有哥哥说一下啊

2020/7/30 18:32
加载中...