随机 hash 0 分求调
查看原帖
随机 hash 0 分求调
675466
zzx0102楼主2023/5/3 15:38
#include<bits/stdc++.h>
using namespace std;
#define W while
#define gc getchar
void Read(int &x) {
	x = 0; char ch = gc();
	W(ch < '0' || ch > '9') ch = gc();
	W(ch >= '0' && ch <= '9') x = x * 10 + (ch ^ 48), ch = gc();
}
#define ull unsigned long long
const int N = 100010; int n, q, ans; unordered_map<int, ull> lsh; ull h[N];
ull L(int x) {
	if(lsh[x]) return lsh[x];
	return lsh[x] = rand() * rand() * rand();
}
int main() {
	srand(time(0)); Read(n); Read(q);
	for(int i = 1; i <= n; i++) {
		int k; Read(k); h[i] = 1;
		W(k--) {int x; Read(x); h[i] *= L(x);}
	}
	for(int i = 1; i <= q; i++) {
		int op, x, y; Read(op); Read(x), Read(y);
		if(op == 1) h[y] *= h[x];
		else {if(h[x] == h[y]) ans ^= i;}
	}
	cout << ans;
	return 0;
}

样例过了

2023/5/3 15:38
加载中...