QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#86174#4000. Dynamic ReachabilityAFewSunsWA 20ms11356kbC++143.2kb2023-03-09 14:48:512023-03-09 14:49:10

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-09 14:49:10]
  • 评测
  • 测评结果:WA
  • 用时:20ms
  • 内存:11356kb
  • [2023-03-09 14:48:51]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
namespace my_std{
	#define ll long long
	#define bl bool
	ll my_pow(ll a,ll b,ll mod){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res=(res*a)%mod;
			a=(a*a)%mod;
			b>>=1;
		}
		return res;
	}
	ll qpow(ll a,ll b){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res*=a;
			a*=a;
			b>>=1;
		}
		return res;
	}
	#define db double
	#define pf printf
	#define pc putchar
	#define fr(i,x,y) for(register ll i=(x);i<=(y);i++)
	#define pfr(i,x,y) for(register ll i=(x);i>=(y);i--)
	#define go(u) for(ll i=head[u];i;i=e[i].nxt)
	#define enter pc('\n')
	#define space pc(' ')
	#define fir first
	#define sec second
	#define MP make_pair
	#define il inline
	#define inf 8e18
	#define random(x) rand()*rand()%(x)
	#define inv(a,mod) my_pow((a),(mod-2),(mod))
	il ll read(){
		ll sum=0,f=1;
		char ch=0;
		while(!isdigit(ch)){
			if(ch=='-') f=-1;
			ch=getchar();
		}
		while(isdigit(ch)){
			sum=sum*10+(ch^48);
			ch=getchar();
		}
		return sum*f;
	}
	il void write(ll x){
		if(x<0){
			x=-x;
			pc('-');
		}
		if(x>9) write(x/10);
		pc(x%10+'0');
	}
	il void writeln(ll x){
		write(x);
		enter;
	}
	il void writesp(ll x){
		write(x);
		space;
	}
}
using namespace my_std;
#define ull unsigned long long
ll n,m,q,head[50050],cnt=0,col[100010];
ll id[110],tot=0,mp[50050],in[50050],dfn[50050],cntt=0;
ull f[50050];
bl ck[100010],pd[110];
struct Edge{
	ll u,v;
}E[100010];
struct edge{
	ll nxt,to;
}e[100010];
struct node{
	ll opt,u,v;
}p[100010];
void add(ll u,ll v){
	e[++cnt].nxt=head[u];
	e[cnt].to=v;
	head[u]=cnt;
}
void bfs(){
	queue<ll> Q;
	fr(i,1,n) if(!in[i]) Q.push(i);
	while(!Q.empty()){
		ll u=Q.front();
		Q.pop();
		dfn[u]=++cntt;
		go(u){
			ll v=e[i].to;
			in[v]--;
			if(!in[v]) Q.push(v);
		}
	}
}
il bl cmp(ll x,ll y){
	return dfn[E[x].u]<dfn[E[x].v];
}
int main(){
	n=read();
	m=read();
	q=read();
	fr(i,1,m){
		ll u=read(),v=read();
		add(u,v);
		col[i]=1;
		E[i].u=u;
		E[i].v=v;
		in[v]++;
	}
	fr(i,1,q){
		p[i].opt=read();
		p[i].u=read();
		if(p[i].opt==2) p[i].v=read();
	}
	bfs();
	fr(i,1,n) assert(dfn[i]);
	if(n>10) return 0;
	for(ll i=1;i<=q;i+=64){
		ll ed=min(q,i+63);
		tot=0;
		fr(j,1,n) f[j]=0;
		fr(j,i,ed){
			if(p[j].opt==1){
				id[++tot]=p[j].u;
				mp[E[p[j].u].u]=j-i;
				ck[p[j].u]=1;
				f[E[p[j].u].u]=1ull<<(j-i);
			}
			else{
				mp[p[j].v]=j-i;
				f[p[j].v]=1ull<<(j-i);
			}
		}
		sort(id+1,id+tot+1,cmp);
		pfr(u,cntt,1){
			for(ll j=head[u];j;j=e[j].nxt){
				ll v=e[j].to;
				if(ck[j]||!col[j]) continue;
				f[u]|=f[v];
			}
		}
		fr(j,i,ed){
			if(p[j].opt==1) col[p[j].u]^=1;
			else{
				bl ans=0;
				fr(k,1,tot) pd[k]=0;
				fr(k,1,tot){
					if((f[p[j].u]>>mp[E[id[k]].u])&1) pd[k]=1;
					fr(l,1,k-1) if(pd[l]&&((f[E[id[l]].v]>>mp[E[id[k]].u])&1)) pd[k]=1;
					if(!col[id[k]]) pd[k]=0;
				}
				if((f[p[j].u]>>mp[p[j].v])&1) ans=1;
				fr(k,1,tot) if(pd[k]&&((f[E[id[k]].v]>>mp[p[j].v])&1)) ans=1;
				if(ans) pf("YES\n");
				else pf("NO\n");
			}
		}
		fr(j,i,ed) if(p[j].opt==1) ck[p[j].u]=0;
	}
}
/*
5 6 3
1 2
1 3
2 4
3 4
3 5
4 5
1 3
1 4
2 1 4
ans:
NO
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5496kb

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
Wrong Answer
time: 20ms
memory: 11356kb

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:


result:

wrong answer 1st lines differ - expected: 'NO', found: ''