QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#811956#9810. Obliviate, Then Reincarnate275307894a#WA 0ms22348kbC++142.2kb2024-12-13 09:46:532024-12-13 09:46:53

Judging History

This is the latest submission verdict.

  • [2024-12-13 09:46:53]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 22348kb
  • [2024-12-13 09:46:53]
  • Submitted

answer

#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=5e5+5,M=N*4+5,K=1000+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(28382);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
	Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
	Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
	#ifdef LOCAL
	#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
	#else 
	#define gdb(...) void()
	#endif
}using namespace Debug;
int n,m,q,scc[N],k;
vector<pii> S[N];
namespace Tarjan{
	int dfn[N],low[N],dh,st[N],sh;
	void Tarjan(int x){
		dfn[x]=low[x]=++dh;st[++sh]=x;
		for(auto [i,w]:S[x]){
			if(!dfn[i]) Tarjan(i),low[x]=min(low[x],low[i]);
			else if(!scc[i]) low[x]=min(low[x],dfn[i]);
		}
		if(low[x]==dfn[x]){
			++k;while(st[sh+1]^x) scc[st[sh--]]=k;
		}
	}
	void build(){
		for(int i=1;i<=n;i++) if(!dfn[i]) Tarjan(i);
	}
}
int vis[N];
ll w[N];
int su[N];
void dfs(int x,ll d){
	if(vis[x]){
		if(d^w[x]) su[scc[x]]=1;
		return;
	}
	vis[x]=1;w[x]=d;
	for(auto [i,w]:S[x]) if(scc[x]==scc[i]) dfs(i,d+w);
}
int getans(int x){
	if(su[scc[x]]) return su[scc[x]];
	if(vis[x]) return 0;
	vis[x]=1;
	for(auto [i,w]:S[x]) if(getans(i)) return su[scc[x]]=1;
	return 0;
}
void Solve(){
	scanf("%d%d%d",&n,&m,&q);
	for(int i=1;i<=m;i++){
		int a,b;scanf("%d%d",&a,&b);
		S[(a%n+n)%n].emplace_back(((a+b)%n+n)%n,b);
	} 
	Tarjan::build();
	gdb(1);
	for(int i=1;i<=n;i++) if(!vis[i]) dfs(i,0);
	Me(vis,0);
	for(int i=1;i<=n;i++) getans(i);
	while(q--){
		int x;scanf("%d",&x);
		x=(x%n+n)%n;
		puts(su[scc[x]]?"Yes":"No");
	}
}
int main(){
	int t=1;
	// scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 2 3
1 1
-1 3
1
2
3

output:

Yes
Yes
No

result:

ok 3 tokens

Test #2:

score: 0
Accepted
time: 0ms
memory: 22312kb

input:

3 2 3
1 1
-1 0
1
2
3

output:

No
No
No

result:

ok 3 tokens

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 22348kb

input:

1 1 1
0 1000000000
-1000000000

output:

No

result:

wrong answer 1st words differ - expected: 'Yes', found: 'No'