QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#431652 | #4000. Dynamic Reachability | xlwang | RE | 3ms | 14368kb | C++14 | 4.4kb | 2024-06-05 20:58:34 | 2024-06-05 20:58:35 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define fr(i,j,k) for(register int i=j;i<=k;++i)
#define rf(i,j,k) for(register int i=j;i>=k;--i)
#define foredge(i,j) for(register int i=head[j];i;i=e[i].nxt)
#define pb push_back
#define Times printf("Time:%.3lf\n",clock()/CLOCKS_PER_SEC)
#define pii pair<int,int>
#define mk make_pair
using namespace std;
inline int read(){
int x=0;
bool f=0;
char c=getchar();
while(!isdigit(c)) f|=(c=='-'),c=getchar();
while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar();
return f?-x:x;
}
inline void write(int x){
if(x<0){putchar('-');x=-x;}
if(x>9)write(x/10);
putchar(x%10+'0');
}
inline void writeln(int x){write(x); puts("");}
inline void writepl(int x){write(x); putchar(' ');}
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline int randfind(int l,int r){return rnd()%(r-l+1)+l;}
//inline void init(){
// int t=read();
// while(t--) work();
//}
const int Maxn=1e5+10,B=4e2,Maxb=810;
struct node{
int nxt,to,id;
}e[Maxn<<1];
int head[Maxn],cnt;
inline void add(int u,int v,int w){++cnt;e[cnt]=(node){head[u],v,w};head[u]=cnt;}
int dfn[Maxn],low[Maxn],idx,vis[Maxn],col[Maxn],color;
vector<int> stk;
int chs[Maxn],ok[Maxn];
inline void tarjin(int x){
dfn[x]=low[x]=++idx;vis[x]=1;stk.pb(x);
for(register int i=head[x];i;i=e[i].nxt){
if(chs[e[i].id] || !ok[e[i].id]) continue;
int y;y=e[i].to;
// cout<<"*"<<x<<' '<<y<<endl;
if(!dfn[y]){
tarjin(y);
low[x]=min(low[x],low[y]);
}
else if(vis[y]) low[x]=min(low[x],dfn[y]);
}
if(dfn[x]==low[x]){
++color;
int now;
do{
now=stk.back();stk.pop_back();
col[now]=color;vis[now]=0;
}while(now!=x);
}
}
int n,m,q;
int X[Maxn],Y[Maxn];
inline void init(){
n=read();m=read();q=read();
fr(i,1,m) X[i]=read(),Y[i]=read();
fr(i,1,m) add(X[i],Y[i],i);
// cerr<<"**"<<endl;
}
struct Query{
int tp,x,y;
}que[Maxn];
bitset<Maxb> f[Maxn];
vector<int> vc[Maxn];
vector<pii> uped[Maxn];
int val[Maxn],toid[Maxn];
int nod;
inline void getans(int x,int y){
bitset<Maxb> Ans,now;Ans.reset();queue<int> q;
q.push(x);Ans[x]=1;
while(!q.empty()){
int tmp=q.front();q.pop();
for(auto p:uped[x]){
if(ok[p.second] && !Ans[p.first]) Ans[p.first]=1,q.push(p.first);
}
now=f[toid[x]]&(~Ans);now[nod+1]=1;
for(int p=now._Find_first();p<=nod;p=now._Find_next(p)) q.push(p),Ans[p]=1;
}
// cout<<Ans[y]<<endl;
if(Ans[y]==1) puts("YES");
else puts("NO");
return;
}
inline void solve(int l,int r){
color=idx=0;fr(i,1,n) col[i]=dfn[i]=low[i]=vis[i]=0;
vector<int> ID;
fr(i,l,r) if(que[i].tp==1 && !chs[que[i].x]) chs[que[i].x]=1,ID.pb(que[i].x);
// fr(i,1,m) cout<<i<<' '<<chs[i]<<endl;
fr(i,1,n) if(!dfn[i]) tarjin(i);
// fr(i,1,n) cout<<i<<' '<<col[i]<<endl;
nod=0;
fr(i,l,r) if(que[i].tp==2){
if(!val[col[que[i].x]]){
val[col[que[i].x]]=++nod;
toid[nod]=col[que[i].x];
}
if(!val[col[que[i].y]]){
val[col[que[i].y]]=++nod;
toid[nod]=col[que[i].y];
}
}
fr(i,1,color) f[i].reset();
fr(i,1,nod) f[toid[i]][i]=1;
fr(i,1,color) vector<int> ().swap(vc[i]);
fr(i,1,m) if(ok[i] && !chs[i] && col[X[i]]!=col[Y[i]]){
vc[col[X[i]]].pb(col[Y[i]]);
}
fr(i,1,color) for(auto y:vc[i]) f[i]|=f[y];
fr(i,1,nod) vector<pii> ().swap(uped[i]);
for(auto i:ID) if(col[X[i]]!=col[Y[i]]) uped[col[X[i]]].pb(mk(col[Y[i]],i));
fr(i,l,r){
if(que[i].tp==1) ok[que[i].x]^=1;
else getans(val[col[que[i].x]],val[col[que[i].y]]);
}
fr(i,l,r) if(que[i].tp==1) chs[que[i].x]=0;
}
inline void work(){
fr(i,1,m) ok[i]=1;
// cerr<<"**"<<endl;
fr(i,1,q){
// cerr<<i<<endl;
que[i].tp=read();
if(que[i].tp==1) que[i].x=read();
else que[i].x=read(),que[i].y=read();
}
// cerr<<"***"<<endl;
int l=1,r;
while(l<=q){
r=min(l+B-1,q);
// cerr<<l<<' '<<r<<endl;
// cout<<l<<' '<<r<<endl;
solve(l,r);
l=r+1;
}
}
signed main(){
// freopen("input.in","r",stdin);
// freopen("output.out","w",stdout);
init();work();
// printf("\nTIME:%.3lf",(double)clock()/CLOCKS_PER_SEC);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 14368kb
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
Runtime Error
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 ...