QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#780724#9810. Obliviate, Then Reincarnatehhhyh#WA 201ms40068kbC++234.1kb2024-11-25 12:48:202024-11-25 12:48:21

Judging History

This is the latest submission verdict.

  • [2024-11-26 23:19:26]
  • hack成功,自动添加数据
  • (/hack/1260)
  • [2024-11-25 12:48:21]
  • Judged
  • Verdict: WA
  • Time: 201ms
  • Memory: 40068kb
  • [2024-11-25 12:48:20]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define all(x) x.begin(), x.end()
void solve()
{
    int n, m, q;
    cin >> n >> m >> q;
    vector<int> f(n), ok(n, 1);
    iota(all(f), 0ll);
    auto find = [&](auto find, int x) -> int
    {
        return f[x] == x ? f[x] : f[x] = find(find, f[x]);
    };
    vector<int> d(n);
    vector<vector<pair<int, int>>> e(n);
    vector<vector<pair<int, int>>> g(n);
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        int w = b;
        a = (a % n + n) % n;
        if (b == 0)
            continue;
        b = (b % n + n) % n;
        b = (b + a) % n;
        e[a].push_back({b, w});
        g[b].push_back({a, w});
        d[a]++;
    }
    {
        queue<int> q;
        for (int i = 0; i < n; i++)
        {
            if (d[i] == 0)
            {
                q.push(i);
            }
        }
        while (!q.empty())
        {
            int x = q.front();
            q.pop();
            ok[x] = 0;
            for (auto [y, w] : g[x])
            {
                d[y]--;
                if (d[y] == 0)
                {
                    q.push(y);
                }
            }
        }
        vector<vector<int>> p(n);
        for (int i = 0; i < n; i++)
        {
            for (auto [y, w] : e[i])
            {
                if (ok[i] && ok[y])
                {
                    int a = find(find, i), b = find(find, y);
                    f[b] = a;
                }
            }
        }
        for (int i = 0; i < n; i++)
        {
            if (ok[i])
                p[find(find, i)].push_back(i);
        }
        vector<vector<int>> fa(n, vector<int>(21, -1));
        vector<int> dep(n, -1);
        vector<i64> val(n);
        for (int i = 0; i < n; i++)
        {
            if (p[i].empty())
                continue;
            int rt = p[i][0];
            dep[rt] = 0;
            vector<array<int, 3>> edges;
            function<void(int x, int fa)> dfs = [&](int x, int f)
            {
                fa[x][0] = f;
                for (int i = 1; i <= 20; i++)
                {
                    if (fa[x][i - 1] == -1)
                        fa[x][i] = -1;
                    else
                        fa[x][i] = fa[fa[x][i - 1]][i - 1];
                }
                for (auto [y, w] : e[x])
                {
                    if (!ok[y])
                        continue;
                    if (dep[y] != -1)
                    {
                        edges.push_back({x, y, w});
                        continue;
                    }
                    dep[y] = dep[x] + 1;
                    val[y] = val[x] + w;
                    dfs(y, x);
                }
            };
            function<int(int x, int y)> getfa = [&](int x, int y)
            {
                if (dep[x] < dep[y])
                    swap(x, y);
                for (int i = 20; ~i; i--)
                    if (fa[x][i] != -1 && dep[fa[x][i]] >= dep[y])
                        x = fa[x][i];
                if (x == y)
                    return x;
                for (int i = 20; ~i; i--)
                    if (fa[x][i] != fa[y][i])
                        x = fa[x][i], y = fa[y][i];
                return fa[x][0];
            };
            dfs(rt, -1);
            int t = 0;
            for (auto [x, y, w] : edges)
            {
                int f = getfa(x, y);
                i64 v = val[x] + val[y] - 2 * val[f];
                if (v + w != 0)
                {
                    t = 1;
                    break;
                }
            }
            for (auto y : p[i])
                ok[y] = t;
        }
    }
    for (int i = 0; i < q; i++)
    {
        int x;
        cin >> x;
        x = (x % n + n) % n;
        if (ok[x])
            cout << "Yes\n";
        else
            cout << "No\n";
    }
}
signed main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int T = 1;
    while (T--)
        solve();
}
/*
 3 2 3
 1 1
 -1 0
 1
 2
 3
*/

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3628kb

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: 3552kb

input:

1 1 1
0 1000000000
-1000000000

output:

Yes

result:

ok "Yes"

Test #4:

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

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: 201ms
memory: 40068kb

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'