QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#628682#8237. Sugar Sweet IIAlbert711WA 122ms7692kbC++202.3kb2024-10-10 21:41:322024-10-10 21:41:32

Judging History

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

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

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;
}
int jj;
vector<int> a;
vector<int> ans;
vector<int> b;
vector<int> w;
vector<int> in;
vector<int> idx;
vector<vector<int> > ed;
int cnt=0;
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);
    idx=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];
    // ++cnt;
    // if(jj==8960){
    //     if(cnt==15){
    //         for(int i=1;i<=n;i++)cout<<a[i]<<" \n"[i==n];
    //         for(int i=1;i<=n;i++)cout<<b[i]<<" \n"[i==n];
    //         for(int i=1;i<=n;i++)cout<<w[i]<<" \n"[i==n];
    //     }
    //     return;
    // }
    for(int i=1;i<=n;i++){
        if(b[i]==i) {
            
        }else if(a[b[i]]>a[i]){
            a[i]+=w[i]%mod;
            idx[i]=1;
        }else if(a[b[i]]+w[b[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();
        for(auto i:ed[now.first]){
            if(idx[now.first]) {
                a[i]=(a[i]+w[i]*inv[now.second+1]%mod)%mod;
                idx[i]=1;
            }
            if(--in[i]==0){
                q.push({i,now.second+1});                
            }
        }
    }
    for(int i=1;i<=n;i++){
        cout<<a[i]%mod<<" \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;
    jj=T;
    while(T--) abt();
    return 0;
}


详细

Test #1:

score: 100
Accepted
time: 5ms
memory: 7404kb

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: 122ms
memory: 7692kb

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 716129253 984444619 489899014 435736558 113628626 865563379 452360358 963066959
665922935 577926775 132646723 421298438 601054667 99438820 8...

result:

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