QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#623442#8237. Sugar Sweet IIZhou_JKWA 111ms27572kbC++141.6kb2024-10-09 12:00:392024-10-09 12:00:41

Judging History

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

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

answer

#include<bits/stdc++.h>
using namespace std;
constexpr int N=500005;
constexpr int MOD=1000000007;
int qpow(int a,int b)
{
    int res=1;
    while(b)
    {
        if(b&1) res=(long long)res*a%MOD;
        a=(long long)a*a%MOD,b>>=1;
    }
    return res;
}
int getinv(int x)
{
    return qpow(x,MOD-2);
}
int fac[N],ifac[N];
void init(int n)
{
    fac[0]=1;
    for(int i=1;i<=n;i++)
        fac[i]=(long long)fac[i-1]*i%MOD;
    ifac[n]=getinv(fac[n]);
    for(int i=n;i>=1;i--)
        ifac[i-1]=(long long)ifac[i]*i%MOD;
    return;
}
int n;
int a[N],b[N],w[N];
int dis[N];
bool vis[N];
vector<int>G[N];
void dfs(int u,int father)
{
    vis[u]=true;
    dis[u]=dis[father]+1;
    for(int v:G[u])
        dfs(v,u);
    return;
}
void solve()
{
    cin>>n;
    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++)
        vis[i]=false,G[i].clear();
    for(int i=1;i<=n;i++)
    {
        if(a[i]<a[b[i]]) vis[i]=true;
        else if(a[i]>=a[b[i]]+w[b[i]]) vis[i]=false;
        else G[b[i]].emplace_back(i);
    }
    for(int i=1;i<=n;i++)
        if(vis[i]) dfs(i,0);
    for(int i=1;i<=n;i++)
    {
        int ans=0;
        if(vis[i]) ans=(a[i]+(long long)ifac[dis[i]]*w[i])%MOD;
        else ans=a[i];
        cout<<ans<<" ";
    }
    cout<<"\n";
    return;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
    init(500000);
    int T;
    cin>>T;
    while(T--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 25456kb

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: 111ms
memory: 27572kb

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 986091180 234208588 859123744 
863886789 
871186919 814243920 968784984 206455474 341020407 449261413 196759729 901433117 519383814 907574792 983760005 984444619 489899014 435736558 113628626 977360756 452360358 963066959 
665922935 577926775 132646723 421298438 601054667 9943882...

result:

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