QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#690218#8237. Sugar Sweet IICMingWA 371ms13008kbC++141.2kb2024-10-30 21:04:102024-10-30 21:04:12

Judging History

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

  • [2024-11-04 16:59:03]
  • hack成功,自动添加数据
  • (/hack/1109)
  • [2024-10-30 21:04:12]
  • 评测
  • 测评结果:WA
  • 用时:371ms
  • 内存:13008kb
  • [2024-10-30 21:04:10]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 5e5 + 5;
int a[N], b[N], w[N];
int p[N];
const int mod = 1e9 + 7;
int f[N];
int n; 
LL qmi(LL x, LL k)
{
    LL res = 1;
    while(k)
    {
        if(k & 1) res = res * x % mod;
        k >>= 1;
        x = x * x % mod;
    }
    return res % mod;
}
bool st[N];
int dfs(int u)
{
    st[u] = true;
    int j = b[u];
    if(a[u] < a[j]) p[u] = 1;
    else if(a[u] >= a[j] + w[j]) p[u] = 0;
    else
    {
        if(st[j]) return p[u] = 0;
        int t = dfs(j);
        if(!t)p[u] = 0;
        else p[u] = t + 1;
    }
    return p[u];
}
void solve()
{
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i], st[i] = false;
    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(!st[i]) dfs(i);
        // cout << p[i] << " ";
        int t = 0;
        if(p[i]) t = qmi(f[p[i]], mod - 2);
        cout << (a[i] + t * w[i] % mod) % mod << " ";
    }

    cout << "\n";
}

int main()
{
    f[0] = 1;
    for(int i = 1; i < N; i++) f[i] = f[i - 1] * i % mod;
    int t; cin >> t;
    while(t--)
        solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 13008kb

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: 371ms
memory: 12720kb

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 892620793 578579275 859123744 
863886789 
871186919 814243920 968784984 206455474 694033700 449261413 -151639591 901433117 519383814 907574792 983760005 984444619 489899014 435736558 113628626 977360756 512133948 963066959 
665922935 577926775 -340671849 421298438 601054667 99438...

result:

wrong answer 3rd numbers differ - expected: '590444253', found: '892620793'