记录编号 577292 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 [CSP 2022S]星战 最终得分 100
用户昵称 Gravataryrtiop 是否通过 通过
代码语言 C++ 运行时间 2.290 s
提交时间 2022-10-30 19:47:31 内存使用 10.31 MiB
显示代码纯文本
// Problem: P8819 [CSP-S 2022] 星战(暂无数据)
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P8819?contestId=90216
// Memory Limit: 512 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
using i64 = long long;

const int p = 131;
const i64 mod = 998244353;
const int maxn = 5e5 + 5;
int n,m;
i64 val[maxn],sum[maxn],lst[maxn];

int main() {
	freopen("csp2022_galaxy.in","r",stdin);
	freopen("csp2022_galaxy.out","w",stdout);
	scanf("%d %d",&n,&m);
	i64 tot = 0;
	val[0] = 1;
	for(int i = 1;i <= n;++ i) {
		val[i] = 1ll * val[i - 1] * p % mod;
		tot += val[i];
	}
	for(int i = 1;i <= m;++ i) {
		int u,v;
		scanf("%d %d",&u,&v);
		sum[v] += val[u];
	}
	i64 ans = 0;
	for(int i = 1;i <= n;++ i) {
		ans += lst[i] = sum[i];
	}
	
	int Q;
	scanf("%d",&Q);
	while(Q --) {
		int op,u,v;
		scanf("%d %d",&op,&u);
		if(op == 1) {
			scanf("%d",&v);
			sum[v] -= val[u];
			ans -= val[u];
		}
		else if(op == 2) {
			ans -= sum[u];
			sum[u] = 0;
		}
		else if(op == 3) {
			scanf("%d",&v);
			sum[v] += val[u];
			ans += val[u];
		}
		else {
			ans += lst[u] - sum[u];
			sum[u] = lst[u];
		}
		if(ans == tot)puts("YES");
		else puts("NO");
	}
	return 0;
}