QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#786470 | #9810. Obliviate, Then Reincarnate | Empty_Dust | WA | 187ms | 22076kb | C++23 | 3.7kb | 2024-11-26 21:40:36 | 2024-11-26 21:40:37 |
Judging History
This is the latest submission verdict.
- [2024-11-26 23:19:26]
- hack成功,自动添加数据
- (/hack/1260)
- [2024-11-26 21:40:36]
- Submitted
answer
#include <bits/stdc++.h>
#define ranges std::ranges
#define views std::views
using u32 = unsigned;
using i64 = long long;
using u64 = unsigned long long;
using pii = std::pair<int, int>;
using a3 = std::array<int, 3>;
using a4 = std::array<int, 4>;
const int N = 1e6;
const int MAXN = 1e6 + 10;
const int inf = 1e9;
// const int mod = 1e9 + 7;
const int mod = 998244353;
struct SCC {
int n;
std::vector<std::vector<int>> adj;
std::vector<int> stk;
std::vector<int> dfn, low, bel;
int cur, cnt;
std::vector<int> huan;
SCC() {}
SCC(int n) {
init(n);
}
void init(int n) {
this->n = n;
adj.assign(n, {});
dfn.assign(n, -1);
low.resize(n);
bel.assign(n, -1);
stk.clear();
cur = cnt = 0;
}
void addEdge(int u, int v) {
if (u == v) {
huan.push_back(u);
return;
}
adj[u].push_back(v);
}
void dfs(int x) {
dfn[x] = low[x] = cur++;
stk.push_back(x);
for (auto y : adj[x]) {
if (dfn[y] == -1) {
dfs(y);
low[x] = std::min(low[x], low[y]);
}
else if (bel[y] == -1) {
low[x] = std::min(low[x], dfn[y]);
}
}
if (dfn[x] == low[x]) {
int y;
do {
y = stk.back();
bel[y] = cnt;
stk.pop_back();
} while (y != x);
cnt++;
}
}
std::vector<int> work() {
for (int i = 0; i < n; i++) {
if (dfn[i] == -1) {
dfs(i);
}
}
int m = n / 2;
std::vector<int> ans(n), vis(n);
for (int i = 0;i < m;++i) {
if (bel[i] == bel[i + m]) {
vis[i] = vis[i + m] = 1;
ans[i] = ans[i + m] = 1;
// std::cout << i << ' ';
}
}
for (int x : huan) {
ans[x] = 1;
vis[x] = 1;
}
auto dfs2 = [&](auto&& self, int u, int p) ->bool {
if (vis[u])return ans[u];
vis[u] = 1;
for (int v : adj[u])if (v != p) {
if (self(self, v, u)) {
ans[u] = 1;
}
}
return ans[u];
};
for (int i = 0;i < n;++i) {
if (!vis[i])
dfs2(dfs2, i, -1);
}
return ans;
}
};
void solve() {
int n, m, q;std::cin >> n >> m >> q;
SCC scc(2 * n);
int N = 2 * n;
for (int i = 0; i < m;++i) {
int a, b;std::cin >> a >> b;
if (!b)continue;
a = ((a % n) + n) % n;
// if (b % n == 0) {
// scc.addEdge(a, a);
// scc.addEdge(a + n, a + n);
// continue;
// }
// b += a;
// if (b > n)
// b = b % n + n;
// if (b < -n)
// n = b % n - n;
b = ((a + b) % n + N) % N;
scc.addEdge(a, b);
// std::cout << a << ' ' << b << '\n';
scc.addEdge(a + n, ((b + n) % N + N) % N);
// std::cout << a + n << ' ' << ((b + n) % N + N) % N << '\n';
}
// std::cout << (-100 % 7) << '\n';
auto ans = scc.work();
for (int i = 0;i < q;++i) {
int x;std::cin >> x;
x = (x % n + n) % n;
std::cout << (ans[x] ? "Yes" : "No") << '\n';
}
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0), std::cout.tie(0);
int t = 1;
while (t--) {
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3788kb
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: 3536kb
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: 3488kb
input:
1 1 1 0 1000000000 -1000000000
output:
Yes
result:
ok "Yes"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
3 2 3 0 1000000000 1 -1000000000 -1000000000 0 -1000000000
output:
No No No
result:
ok 3 tokens
Test #5:
score: -100
Wrong Answer
time: 187ms
memory: 22076kb
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...
output:
Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes ...
result:
wrong answer 1st words differ - expected: 'No', found: 'Yes'