跳到正文

题解

题解:AT_abc403_c [ABC403C] 403 Forbidden

Dead_Fish_eyeS约 1 分钟
原文

这是 2025年12月6日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2025年12月6日
收录
2025年12月12日
更新
2026年11月21日
篇幅
约 1 分钟

版本

  1. v2当前
  2. v1

题解:AT_abc403_c [ABC403C] 403 Forbidden

思路

由题可知,有三种操作:

  1. 让 xx 能访问 yy 网站。
  2. 让 xx 能访问全部网站。
  3. 查询 xx 是否能访问 yy 网站。

因为 set 插入时可以去重,于是我们用 nn 个 set 维护每个 xx 能访问的网站。
对于每个都能访问的 xx,我们用 bool 数组进行维护。
对于查询操作,如果这个 xx 可以访问每个网站,或者 xx 可以访问 yy,输出 Yes,否则,输出 No。

附上代码:

C++
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
set<int>s[N];int n,m,q,op,x,y;bool f[N]={0};
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m>>q;
	while(q--){
		cin>>op>>x;
		if(op==1)cin>>y,s[x].insert(y);
		if(op==2)f[x]=1;
		if(op==3){cin>>y;if(f[x]||s[x].count(y)/*y在set中为正数,不在为0*/)cout<<"Yes\n";else cout<<"No\n";}
	}
	return 0;
}

完结撒花。