QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#696607#8237. Sugar Sweet IICatreapWA 0ms3852kbC++232.4kb2024-10-31 23:47:012024-10-31 23:47:03

Judging History

你现在查看的是最新测评结果

  • [2024-11-04 16:59:03]
  • hack成功,自动添加数据
  • (/hack/1109)
  • [2024-10-31 23:47:03]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3852kb
  • [2024-10-31 23:47:01]
  • 提交

answer

#include <bits/stdc++.h>

using ll = long long;

const ll M = 1e9 + 7;

ll qpow(ll a, ll b) {
    ll ret = 1;
    while (b) {
        if (b & 1) {
            ret = (ret * a) % M;
        }
        a = (a * a) % M;
        b >>= 1;
    }
    return ret;
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    ll T;
    std::cin >> T;
    ll inv = qpow(2, M - 2);
    while (T--) {
        ll n;
        std::cin >> n;
        std::vector<ll> a(n + 1);
        std::vector<ll> b(n + 1);
        std::vector<ll> w(n + 1);
        std::vector<bool> vis(n + 1);
        std::vector<ll> dp(n + 1), p(n + 1);
        std::vector<ll> stk;
        ll top = 0;
        for (ll i = 1; i <= n; i++) {
            std::cin >> a[i];
        }
        for (ll i = 1; i <= n; i++) {
            std::cin >> b[i];
        }
        for (ll i = 1; i <= n; i++) {
            std::cin >> w[i];
        }
        auto work = [&](auto&& self, ll i) -> void {
            if (vis[i]) {
                while (top--) {
                    dp[stk[top]] = a[stk[top]];
                    p[stk[top]] = 0;
                }
                return;
            }
            vis[i] = true;
            if (a[i] < a[b[i]]) {
                p[i] = 1;
                dp[i] = a[i] + w[i];
            } else if (a[i] >= a[b[i]] + w[b[i]]) {
                p[i] = 0;
                dp[i] = a[i];
            } else {
                self(self, b[i]);
                p[i] = ((p[b[i]] * (a[b[i]] + w[b[i]] > a[i] ? 1 : 0) +
                         ((1 - p[b[i]] + M) % M * (a[b[i]] > a[i] ? 1 : 0)))) %
                       M;
                dp[i] =
                    a[i] +
                    inv *
                        (p[b[i]] * (a[b[i]] + w[b[i]] > a[i] ? w[i] : 0) +
                         ((1 - p[b[i]] + M) % M * (a[b[i]] > a[i] ? w[i] : 0)));
            }
        };
        for (ll i = 1; i <= n; i++) {
            if (vis[i]) {
                continue;
            }
            if (b[i] == i) {
                vis[i] = true;
                dp[i] = a[i];
                p[i] = 0;
                continue;
            }
            work(work, i);
        }
        for (ll i = 1; i <= n; i++) {
            printf(" %lld" + !(i - 1), dp[i]);
        }
        printf("\n");
    }
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3852kb

input:

4
4
2 5 5 2
4 2 1 3
3 2 1 4
3
5 4 3
1 1 1
6 6 6
3
5 4 3
2 3 1
1 2 3
5
2 1 3 2 1
5 1 1 3 4
1 3 4 2 4

output:

1500000014 5 5 6
5 10 9
500000009 1000000012 6
500000006 4 3 4 5

result:

wrong answer 1st numbers differ - expected: '500000007', found: '1500000014'