QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#691508#8237. Sugar Sweet IImiaomiaomiao#WA 378ms26036kbC++171.9kb2024-10-31 11:44:272024-10-31 11:44:29

Judging History

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

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

answer

#include <bits/stdc++.h>
using namespace std;

#define rep(i,x) for (int i=0;i<(int)x;i++)
#define fore(i,x) for (auto &i:x)
#define For(i,x) for (int i=1;i<=(int)x;i++)
#define ll long long
#define vi vector<int>
#define pii pair<int,int>

const int mod = 1e9+7;

vector<int> jc;
vector<int> inv;

const int MAXN = 5e5+3;

int ksm(int x,int y){
    int res=1;
    while(y){
        if(y&1) res=(ll)res*x%mod;
        x=(ll)x*x%mod; y>>=1;
    }
    return res;
}

ll calc_inv(const int &x){
    if (x==0) return 1;
    return ksm(x,mod-2);
}

void pre(int x){
    jc.resize(x+5);
    inv.resize(x+5);
    jc[0]=1;
    for(int i=1;i<=x;++i) jc[i]=(ll)jc[i-1]*i%mod;
    inv[x]=ksm(jc[x],mod-2);
    for(int i=x-1;i>=0;--i) inv[i]=(ll)inv[i+1]*(i+1)%mod;
}

int C(int x,int y){
    if(x<y) return 0;
    return (ll)jc[x]*inv[y]%mod*inv[x-y]%mod;
}

int n;
int a[MAXN],b[MAXN],w[MAXN];
int ans[MAXN];
// int in[MAXN],out[MAXN];
vi g[MAXN];
ll INV;

void go(const int&x, const int &dep){
    // ans[]
    ll poss = C(n,dep) * jc[n-dep] % mod;
    ll val = (poss * w[x] %mod + jc[n] * a[x] % mod) % mod * INV % mod;
    ans[x]=val;

    fore(i,g[x]) go(i,dep+1);
}

void solve(){
    cin>>n;
    INV=calc_inv(jc[n]);
    rep(i,n){
        g[i].resize(0);
        // in[i]=0;
        // out[i]=0;
        ans[i]=-1;
    }
    rep(i,n) cin>>a[i];
    rep(i,n){
        cin>>b[i];
        b[i]--;
    }
    rep(i,n) cin>>w[i];

    rep(i,n){
        int fa=b[i];
        if (a[fa]+w[fa]>a[i] && a[fa]<=a[i]){
            g[fa].push_back(i);
        }
    }

    rep(i,n){
        int fa=b[i];
        if (a[i]<a[fa]){
            go(i,1);
        }
    }
    rep(i,n){
        if (ans[i]!=-1){
            cout<<ans[i]<<" ";
        }else{
            cout<<a[i]<<" ";
        }
    }
    cout<<endl;
}

int main(){
    int T;
    cin>>T;
    pre(500000);
    while (T--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 26036kb

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: 378ms
memory: 23568kb

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:

286919149 58719651 362326071 400398296 75250648 
863886789 
-594523605 583588631 -801037697 -384644750 808499180 111707654 -14998427 109755706 -569400898 -556897043 983760005 984444619 -247235650 -759229108 -340848934 977360756 932948077 -501703189 
665922935 577926775 158418836 421298438 601054667 ...

result:

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