QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#840275 | #9810. Obliviate, Then Reincarnate | frankly6# | RE | 0ms | 3572kb | C++17 | 1003b | 2025-01-02 16:47:01 | 2025-01-02 16:47:02 |
Judging History
answer
#include<iostream>
#include<cstdio>
using namespace std;
const int MX=500050;
int T, N, M, Q;
int fa[MX];
bool ring[MX];
int read()
{
int r=0, f=1; char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=getchar();}
while(ch>='0'&&ch<='9') {r=r*10+ch-'0'; ch=getchar();}
return r*f;
}
int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
void merge(int x, int y)
{
x=find(x); y=find(y);
if(x==y) ring[y]=1;
fa[x]=y;
}
int main()
{
// freopen("testdata.in","r",stdin);
N=read(); M=read(); Q=read();
for(int i=1;i<=N;i++) fa[i]=i;
for(int i=1;i<=M;i++)
{
int a=read(), b=read();
// cout << "a=" << a << ", b=" << b << '\n';
a=(a%N+N)%N;
if(b==0) continue;
int to=((a+b)%N+N)%N;
merge(a,to);
}
while(Q--)
{
int x=read();
// cout << "x=" << x << '\n';
if(ring[find(x)]) cout << "Yes\n";
else cout << "No\n";
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3568kb
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: 3572kb
input:
3 2 3 1 1 -1 0 1 2 3
output:
No No No
result:
ok 3 tokens
Test #3:
score: -100
Runtime Error
input:
1 1 1 0 1000000000 -1000000000