QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#392370 | #4000. Dynamic Reachability | OccDreamer | TL | 2ms | 10212kb | C++14 | 3.8kb | 2024-04-17 15:13:06 | 2024-04-17 15:13:06 |
Judging History
answer
//code by Emissary
#include<bits/stdc++.h>
#define vc vector
#define db double
#define fi first
#define se second
#define ll long long
#define mk make_pair
#define pb push_back
#define RI register int
#define PI pair<int,int>
#define ull unsigned long long
#define err cerr << " -_- " << endl
#define debug cerr << " ------------------- " << endl
#define input(x) freopen(#x".in","r",stdin)
#define output(x) freopen(#x".out","w",stdout)
#define NO puts("No")
#define YES puts("Yes")
//#define OccDreamer
//#define int long long
using namespace std;
namespace IO{
inline int read(){
int X=0, W=0; char ch=getchar();
while(!isdigit(ch)) W|=ch=='-', ch=getchar();
while(isdigit(ch)) X=(X<<1)+(X<<3)+(ch^48), ch=getchar();
return W?-X:X;
}
inline void write(int x){
if(x<0) x=-x, putchar('-');
if(x>9) write(x/10);
putchar(x%10+'0');
}
inline void sprint(int x){write(x), putchar(32);}
inline void eprint(int x){write(x), putchar(10);}
}using namespace IO;
const int B = 1;
const int MAXN = 1e5+5;
int n, m, q, x[MAXN], y[MAXN], tim, col[MAXN];
int head[MAXN], ne[MAXN], to[MAXN], cnt, idx[MAXN];
int vol[MAXN], ecnt, mark[MAXN];
int op[MAXN], u[MAXN], v[MAXN], stk[MAXN], vis[MAXN], scc, topf;
int L[MAXN], R[MAXN], bel[MAXN], tag[MAXN], low[MAXN>>1], dfn[MAXN>>1];
bool state[MAXN], ins[MAXN];
int headv[MAXN], tov[MAXN], nev[MAXN], cntv;
bitset<B> mp[MAXN>>1], pa[B+2];
inline void add(int x, int y){++cnt;to[cnt]=y;ne[cnt]=head[x];head[x]=cnt;}
inline void addv(int x, int y){++cntv;tov[cntv]=y;nev[cntv]=headv[x];headv[x]=cntv;}
inline void tarjan(int x){
low[x]=dfn[x]=++tim; stk[++topf]=x; ins[x]=1;
for(int i=head[x];i;i=ne[i]){
if(dfn[to[i]]){
if(ins[to[i]]) low[x]=min(low[x],dfn[to[i]]);
}
else tarjan(to[i]), low[x]=min(low[x],low[to[i]]);
}
if(dfn[x]==low[x]){
stk[topf+1]=0; ++scc; headv[scc]=0; mp[scc].reset();
while(stk[topf+1]!=x){
col[stk[topf]]=scc;
if(idx[stk[topf]]) mp[scc][idx[stk[topf]-1]]=1;
ins[stk[topf]]=0; --topf;
}
}
return ;
}
inline void dfs(int x, int t){
vis[x]=t;
for(int i=headv[x];i;i=nev[i]){
if(vis[tov[i]]==t){
mp[x]|=mp[tov[i]];
continue;
}
dfs(tov[i],t); mp[x]|=mp[tov[i]];
}
return ;
}
inline void query(int x, int y){
bitset<B> now=mp[col[x]], cur; cur.reset();
for(int i=1;i<=ecnt;++i)
if(state[vol[i]]){
int idc=vol[i];
pa[idx[u[idc]]-1]=mp[col[u[idc]]]|mp[col[v[idc]]];
}
while(now!=cur){
int pos=(now^cur)._Find_first();
cur[pos]=1; now|=pa[pos];
}
return puts(now[idx[y]-1]?"YES":"NO"), void();
}
inline void solve(int l, int r){
int tot=0, ss=0; cntv=0; tim=0; ecnt=0;
for(int i=l;i<=r;++i){
op[i]=read(); u[i]=read();
if(op[i]==2) v[i]=read(), mark[v[i]]=l, ++ss;
else mark[x[u[i]]]=l, tag[u[i]]=l;
}
if(ss==0){
for(int i=l;i<=r;++i)
state[u[i]]^=1;
return ;
}
for(int i=1;i<=n;++i)
if(mark[i]==l) idx[i]=++tot;
else idx[i]=0;
memset(dfn,0,sizeof dfn); scc=0;
memset(head,0,sizeof head); cnt=0;
for(int i=1;i<=m;++i){
if(tag[i]!=l && state[i]) add(x[i],y[i]);
else if(tag[i]==l) vol[++ecnt]=i;
}
for(int i=1;i<=n;++i) if(!dfn[i]) tarjan(i);
for(int i=1;i<=n;++i)
for(int j=head[i];j;j=ne[j])
if(col[i]!=col[to[j]]) addv(col[i],col[to[j]]);
for(int i=1;i<=scc;++i) if(vis[i]!=l) dfs(i,l);
for(int i=l;i<=r;++i){
if(op[i]==1) state[u[i]]^=1;
else query(u[i],v[i]);
}
return ;
}
inline void solve(){
n=read(), m=read(), q=read();
for(int i=1;i<=m;++i){
x[i]=read(), y[i]=read();
state[i]=1;
}
for(int i=1;i<=q;++i) bel[i]=(i-1)/B+1, R[bel[i]]=i;
for(int i=1;i<=bel[q];++i) L[i]=R[i-1]+1;
for(int i=1;i<=bel[q];++i) solve(L[i],R[i]);
return ;
}
signed main(){
int t=1;
while(t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 10212kb
input:
5 6 7 1 2 1 3 2 4 3 4 3 5 4 5 2 1 5 2 2 3 1 3 1 4 2 1 4 1 3 2 1 5
output:
YES NO NO YES
result:
ok 4 lines
Test #2:
score: -100
Time Limit Exceeded
input:
50000 100000 100000 36671 44121 25592 44321 13226 46463 13060 25694 14021 20087 22881 38333 34655 47774 22868 26462 31154 48710 27491 32365 5874 47497 17622 28600 1886 14193 22315 23656 14973 22704 1335 25384 22612 34915 2852 48213 23334 25519 24342 28784 6238 36125 14598 39494 33069 34250 2123 3059...
output:
NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO ...