QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#789870 | #9810. Obliviate, Then Reincarnate | Cai_Guang | TL | 0ms | 3620kb | C++20 | 1.4kb | 2024-11-27 22:20:45 | 2024-11-27 22:20:51 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int inf=1e18;
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int n,m,q;
cin>>n>>m>>q;
vector<int>vis(n,-inf),res(n,-1ll);
vector<vector<array<int,2>>>e(n);
auto get=[&](int x)->int{
return ((x%n)+n)%n;
};
for(int i=0;i<m;++i){
int x,y;
cin>>x>>y;
if(!y) continue;
e[get(x)].push_back({x,y});
if(y%n==0) res[get(x)]=1;
}
for(int i=0;i<n;++i){
if(res[i]!=-1) continue;
stack<int>st;
auto dfs=[&](auto dfs,int u)->int{
int du=get(u);
st.push(du);
if(res[du]!=-1){
return res[du];
}
if(vis[du]!=-inf){
if(vis[du]==u) return -1;
else return res[du]=1;
}
vis[du]=u;
int b=-1;
for(auto [x,y]:e[du]){
if(dfs(dfs,u+y)==1) b=1;
}
vis[du]=-inf;
return res[du]=b;
};
res[i]=dfs(dfs,i);
while(!st.empty()){
auto u=st.top();
st.pop();
if(res[u]==-1) res[u]=0;
}
}
// for(int i=0;i<n;++i) cerr<<res[i]<<" \n"[i==n-1];
for(int i=0;i<q;++i){
int x;
cin>>x;
cout<<(res[get(x)]?"Yes\n":"No\n");
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3560kb
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: 3616kb
input:
3 2 3 1 1 -1 0 1 2 3
output:
No No No
result:
ok 3 tokens
Test #3:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
1 1 1 0 1000000000 -1000000000
output:
Yes
result:
ok "Yes"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
3 2 3 0 1000000000 1 -1000000000 -1000000000 0 -1000000000
output:
No No No
result:
ok 3 tokens
Test #5:
score: -100
Time Limit Exceeded
input:
50134 500000 500000 -154428638 -283522863 -186373509 -327130969 154999046 46750274 -933523447 349415487 -437683609 140099255 864996699 -262318199 811293034 -264299324 120273173 52410685 874944410 -52048424 445049930 -803690605 -138111276 -104634331 720288580 126597671 471164416 -348777147 -356502322...