社区讨论

红红绿绿加点蓝

P8819[CSP-S 2022] 星战参与者 2已保存回复 4

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
4 条
当前快照
1 份
快照标识符
@mhjifr89
此快照首次捕获于
2025/11/04 03:05
4 个月前
此快照最后确认于
2025/11/04 03:05
4 个月前
查看原帖
CPP
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1e9+7;
const int xx=5e5+5;
int n,m;
vector<int> G[xx];
vector<bool> pd[xx];
int ha[xx];
int now_ans=0;
int ans;
vector<int> g[xx];
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') {
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') {
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
signed main()
{
	srand(time(0));
	n=read(),m=read();
	now_ans=0;
	for(int i=1; i<=n; i++) {
		ha[i]=(1LL*(rand()+1)+(rand()+1))%mod+(2*(rand()+1))%(19178)+1;
		ans=(ans+ha[i])%mod;
	}
	for(int i=1; i<=m; i++) {
		int u=read(),v=read();
		G[v].push_back(u);
		now_ans=(now_ans+ha[u])%mod;
		pd[v].push_back(true);
	}
	int q=read();
	for(int i=1; i<=q; i++) {
		int t=read();
		if(t==1) {
			int u=read(),v=read();
			for(int i=0;i<G[v].size();i++) {
				if(G[v][i]==u && pd[v][i]) {
                    now_ans=(now_ans-ha[u])%mod;
                    pd[v][i]=false;
                    break;
                }
			}
		} else if(t==2) {
			int v=read();
			for(int i=0;i<G[v].size();i++) {
				if(pd[v][i]) {
					now_ans=(now_ans-ha[G[v][i]])%mod;
					pd[v][i]=false;
				}
			}
		} else if(t==3) {
			int u=read(),v=read();
			for(int i=0;i<G[v].size();i++) {
				if(G[v][i]==u && !pd[v][i]) {
                    now_ans=(now_ans+ha[G[v][i]])%mod;
                    pd[v][i]=true;
                    break;
                }
			}
		} else if(t==4) {
			int v=read();
			for(int i=0;i<G[v].size();i++) {
				if(!pd[v][i]) {
					now_ans=(now_ans+ha[G[v][i]])%mod;
					pd[v][i]=true;
				}
			}
		}
		if(now_ans==ans) {
			cout<<"YES"<<"\n";
		} else {
			cout<<"NO"<<"\n";
		}
	}
	return 0;
}
50分代码?有T有W还有C?

回复

4 条回复,欢迎继续交流。

正在加载回复...