QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#786228#9810. Obliviate, Then ReincarnateEmpty_DustRE 0ms0kbC++233.5kb2024-11-26 20:48:292024-11-26 20:48:30

Judging History

This is the latest submission verdict.

  • [2024-11-26 23:19:26]
  • hack成功,自动添加数据
  • (/hack/1260)
  • [2024-11-26 20:48:30]
  • Judged
  • Verdict: RE
  • Time: 0ms
  • Memory: 0kb
  • [2024-11-26 20:48:29]
  • 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;
        if (b % n == 0) {
            scc.addEdge(a, a);
            scc.addEdge(a + n, a + n);
            continue;
        }
        a = ((a % n) + n) % n;
        b = a + b % n;
        scc.addEdge(a, (b % N + N) % N);
        // std::cout << a << ' ' << (b % N + N) % N << '\n';
        scc.addEdge(a + n, ((b + n) % N + N) % N);
        // std::cout << a + n << ' ' << ((b + n) % N + N) % N << '\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: 0
Runtime Error

input:

3 2 3
1 1
-1 3
1
2
3

output:


result: