QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#627976#8237. Sugar Sweet IIAlbert711WA 6ms7512kbC++201.8kb2024-10-10 17:57:062024-10-10 17:57:07

Judging History

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

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

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define db double
const int mod=1e9+7;
const int N=5e5+5;

int inv[N];
int fp(int ba,int pow){
    int r=1;
    while(pow){
        if(pow&1) r=r*ba%mod;
        ba=ba*ba%mod;
        pow>>=1;
    }
    return r;
}
vector<int> a;
vector<int> ans;
vector<int> b;
vector<int> w;
vector<int> in;
vector<vector<int> > ed;
void abt(){
    int n;
    cin>>n;
    ed=vector<vector<int> > (n+1);
    a=vector<int> (n+1);
    ans=vector<int> (n+1);
    b=vector<int> (n+1);
    w=vector<int> (n+1);
    in=vector<int> (n+1);
    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(b[i]==i) continue;
        if(a[b[i]]>a[i]){
            ans[i]=(a[i]+w[i])%mod;
        }else if(a[b[i]]+w[b[i]]<=a[i]){
            ans[i]=a[i];
        }else{
            in[i]++;
            ed[b[i]].push_back(i);
        }
    }
    queue<pair<int,int>> q;
    for(int i=1;i<=n;i++){
        if(in[i]==0) q.push({i,1});
    }
    while(!q.empty()){
        auto now=q.front();
        q.pop();
        ans[now.first]=(a[now.first]+w[now.first]*inv[now.second]%mod)%mod;
        for(auto i:ed[now.first]){
            if(--in[i]==0){
                q.push({i,now.second+1});                
            }
        }
    }
    for(int i=1;i<=n;i++){
        cout<<ans[i]<<" \n"[i==n];
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    int tmp=1;
    for(int i=1;i<=500000;i++){
        tmp=tmp*i%mod;
    }
    tmp=fp(tmp,mod-2);
    for(int i=500000;i>=1;i--){
        inv[i]=tmp;
        tmp=tmp*i%mod;
    }
    int T=1;
    cin>>T;
    while(T--) abt();
    return 0;
}




Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 6ms
memory: 7512kb

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 7 6 6
11 10 9
166666673 5 6
500000006 4 7 4 5

result:

wrong answer 2nd numbers differ - expected: '5', found: '7'