满分了?求hack
查看原帖
满分了?求hack
543427
_sin_楼主2022/11/7 15:21

我的思路也是加法哈希,但是哈希值不是随机数,竟然 AC 了,这应该可以卡吧

#include <bits/stdc++.h>
#define ull unsigned long long
using namespace std;

int n, m, q;
int opt, x, y;
ull sum, ans, val[500005], pos[500005], pos2[500005];
pair<int, int> edge[500005];

int main(){
	srand(time(NULL));
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) sum+=(val[i]=n+i/*rand()*/);
	for (int i = 1; i <= m; i++){
		scanf("%d%d", &edge[i].first, &edge[i].second);
		ans+=val[edge[i].first];
		pos[edge[i].second]+=val[edge[i].first];pos2[edge[i].second] = pos[edge[i].second];
	}
	scanf("%d", &q);
	while(q--){
		scanf("%d", &opt);
		switch(opt){
			case 1:{
				scanf("%d%d", &x, &y);
				pos[y] -= val[x], ans-=val[x];
				break;
			}
			case 2:{
				scanf("%d", &x);
				ans -= pos[x], pos[x]=0;
				break;
			}
			case 3:{
				scanf("%d%d", &x, &y);
				pos[y] += val[x], ans+=val[x];
				break;
			}
			case 4:{
				scanf("%d", &x);
				ans+=pos2[x]-pos[x], pos[x] = pos2[x];
				break;
			}
		}
		if (ans == sum) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}
2022/11/7 15:21
加载中...