QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#638504#8237. Sugar Sweet IIxuemanWA 156ms20056kbC++172.9kb2024-10-13 16:05:002024-10-13 16:05:02

Judging History

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

  • [2024-11-04 16:59:03]
  • hack成功,自动添加数据
  • (/hack/1109)
  • [2024-10-13 16:05:02]
  • 评测
  • 测评结果:WA
  • 用时:156ms
  • 内存:20056kb
  • [2024-10-13 16:05:00]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
const int N = 5e5 + 10;
const int maxn = 1e6 + 10;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;

ll qpow(ll a, ll n)
{
    ll res = 1;
    while (n)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

struct egde
{
    int to, ne;
} e[maxn];
int head[N], ecnt;

void add(int x, int y)
{
    e[++ecnt].to = y;
    e[ecnt].ne = head[x];
    head[x] = ecnt;
}

ll a[N], b[N], w[N];
int fa[N];
bool vis[N];

ll P[N];
ll ans[N];
bool ok = 0;

int getfa(int x)
{
    while (fa[x] != x && fa[x] != 0)
    {
        x = fa[x];
    }
    if (fa[x] == x)
    {
        ok = 1;
    }
    return x;
}

void dfs(int x, int f, int dep, bool op)
{
    vis[x] = 1;
    // cout << w[b[x] ] << ' ' << P[dep] << endl;
    if (!op)
        ans[x] = (P[dep] * w[x] % mod + a[x]) % mod;
    else
        ans[x] = a[x] % mod;
    for (int i = head[x]; i; i = e[i].ne)
    {
        int y = e[i].to;
        if (y == f)
            continue;
        dfs(y, x, dep + 1, op);
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll res = 1;
    for (int i = 1; i < N; i++)
    {
        res = res * i % mod;
        P[i] = qpow(res, mod - 2) % mod;
    }
    int T;
    cin >> T;
    while (T--)
    {
        int n;
        cin >> n;

        for (int i = 0; i <= n; i++)
        {
            head[i] = 0;
            fa[i] = vis[i] = 0;
        }
        ecnt = 0;

        for (int i = 1; i <= n; i++)
            cin >> a[i];
        for (int i = 1; i <= n; i++)
            cin >> b[i];
        for (int i = 1; i <= n; i++)
            cin >> w[i];
        for (int i = 1; i <= n; i++)
        {
            // if (i == b[i]) continue;
            if (a[i] >= a[b[i]] && a[i] < a[b[i]] + w[b[i]])
            {
                add(b[i], i);
                fa[i] = b[i];

                // cout << b[i] << ' ' << i << endl;
            }
        }
        for (int i = 1; i <= n; i++)
        {
            if (!vis[i])
            {
                // if (i == fa[i])
                // {
                //     ans[i] = a[i] % mod;
                //     vis[i] = 1;
                //     continue;
                // }

                if (a[i] >= b[i] + w[b[i]])
                {
                    ans[i] = a[i] % mod;
                    vis[i] = 1;
                    continue;
                }

                ok = 0;
                int root = getfa(i);
                // if (root = 1)
                // cout << root << ' ';
                dfs(root, 0, 1, ok);
            }
        }

        for (int i = 1; i <= n; i++)
            cout << ans[i] << ' ';
        cout << endl;
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 51ms
memory: 20056kb

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:

500000007 5 5 6 
5 10 9 
166666673 5 6 
500000006 4 3 4 5 

result:

ok 15 numbers

Test #2:

score: -100
Wrong Answer
time: 156ms
memory: 20048kb

input:

50000
5
508432375 168140163 892620793 578579275 251380640
3 4 4 1 3
346232959 736203130 186940774 655629320 607743104
1
863886789
1
364158084
18
864679185 463975750 558804051 604216585 694033700 499417132 375390750 337590759 467353355 111206671 983760005 984444619 322277587 138763925 205122047 97736...

output:

508432375 904343293 892620793 578579275 251380640 
863886789 
864679185 463975750 558804051 604216585 694033700 499417132 196759729 901433117 519383814 907574792 983760005 984444619 489899014 435736558 113628626 977360756 482247153 665454200 
665922935 577926775 132646723 421298438 601054667 9943882...

result:

wrong answer 1st numbers differ - expected: '854665334', found: '508432375'