题解:AT_abc403_c [ABC403C] 403 Forbidden

· · 题解

题解:AT_abc403_c [ABC403C] 403 Forbidden

思路

由题可知,有三种操作:

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

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

附上代码:

#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;
}

完结撒花。