QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#617942#8237. Sugar Sweet IIE7kWA 170ms3964kbC++202.0kb2024-10-06 17:48:252024-10-06 17:48:27

Judging History

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

  • [2024-11-04 16:59:03]
  • hack成功,自动添加数据
  • (/hack/1109)
  • [2024-10-06 17:48:27]
  • 评测
  • 测评结果:WA
  • 用时:170ms
  • 内存:3964kb
  • [2024-10-06 17:48:25]
  • 提交

answer

#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define gcd __gcd
using namespace std;
typedef pair<int,int> pii;
const int INF = 9e18;
const int inf = 2e9;
const int N = 2e5 + 10;
const int mod = 1e9 + 7;
int qmi(int a,int k)
{
    int res = 1;
    while(k)
    {
        if(k & 1) res = res * a % mod;
        k >>= 1;
        a = a * a % mod;
    }
    return res;
}
int inv(int x)
{
    return qmi(x,mod-2);
}
int MOD(int x)
{
    return (x % mod + mod) % mod;
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >>t ;
    while(t --)
    {
        int n;
        cin >> n;
        vector<int> a(n + 1),b(n + 1),w(n + 1),cnt(n + 1,1),f(n + 1);
        vector<array<int,2>> e(n + 1);
        f[0] = 1;
        for(int i = 1;i <= n;i ++) f[i] = f[i-1] * i % mod;
        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 ++) e[i] = {a[i],i};
        sort(e.begin()+1,e.end());
        vector<int> vis(n + 1);
        auto dfs =[&](auto &&dfs,int u) -> void
        {
            if(vis[u]) return ;
            vis[u] = 1;
            if(u == b[u])
            {

            }
            else if(a[u] >= a[b[u]] && a[u] < a[b[u]] + w[b[u]])
            {
                dfs(dfs,b[u]);
                cnt[u] += cnt[b[u]];
            }
        };
        
        for(int i = 1;i <= n;i ++) dfs(dfs,e[i][1]);
        vector<int> ans(n + 1);
        for(int i = 1;i <= n;i ++)
        {
            int x = inv(f[cnt[i]]);
            // if(cnt[i] == 1) cout << x << ' ';
            // cout << x << ' ';
            if(cnt[i] != 1)
            ans[i] = a[i] * MOD(1 - x) % mod + (a[i] + w[i]) * x % mod;
            else
            {
                if(a[i] < a[b[i]]) ans[i] = a[i] + w[i];
                else ans[i] = a[i];
            }
            cout << ans[i] % mod << ' ';
        }
        cout << endl;
    }
 }

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3592kb

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: 170ms
memory: 3964kb

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:

854665334 904343293 590444253 906393935 859123744 
863886789 
871186919 814243920 968784984 206455474 17527050 449261413 196759729 901433117 519383814 907574792 983760005 984444619 489899014 435736558 113628626 977360756 482247153 963066959 
902284038 240323331 132646723 421298438 601054667 99438820...

result:

wrong answer 25th numbers differ - expected: '665922935', found: '902284038'