QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#609292#8237. Sugar Sweet IIwsy_jim#WA 140ms22108kbC++142.3kb2024-10-04 11:50:382024-10-04 11:50:42

Judging History

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

  • [2024-11-04 16:59:03]
  • hack成功,自动添加数据
  • (/hack/1109)
  • [2024-10-04 11:50:42]
  • 评测
  • 测评结果:WA
  • 用时:140ms
  • 内存:22108kb
  • [2024-10-04 11:50:38]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdlib>
#include<ctime>
#include<bitset>
#include<vector>
#include<climits>
#include<iomanip>
using namespace std;
#define N 500010
#define int long long
template<typename T>
inline void read(T &x){
    x=0;bool flg=0;char c=getchar();
    for(;!isdigit(c);c=getchar()) if(c=='-') flg=1;
    for(;isdigit(c);c=getchar()) x=x*10+(c^48);
    if(flg) x=-x;
}
const int Mod=1e9+7;

int t;
int n;
int m;
int a[N];
int b[N];
int w[N];
int e[2*N],ne[2*N],idx,h[N];
int d[N],dd[N],inv[N],ans[N];

void add(int a,int b){
    e[idx]=b,ne[idx]=h[a],h[a]=idx++;
}

int fpow(int a,int b){
    int res=1;
    for(;b;b>>=1,a=a*a%Mod) if(b&1) res=res*a%Mod;
    return res;
}

void dfs(int x,int fa,int oo){
    dd[x]=dd[fa]+1;
    if(fa) ans[x]=(oo?inv[dd[x]]:0);
    for(int i=h[x];~i;i=ne[i]){
        int j=e[i];
        if(j==fa) continue;
        dfs(j,x,oo);
    }
}

signed main(){

    read(t);
    while(t--){
        read(n);
        inv[0]=1;idx=0;
        for(int i=1;i<=n;i++) inv[i]=inv[i-1]*i%Mod,ans[i]=0,d[i]=0,dd[i]=0;
        for(int i=1;i<=n;i++) inv[i]=fpow(inv[i],Mod-2);
        for(int i=1;i<=n;i++) read(a[i]),h[i]=-1;
        for(int i=1;i<=n;i++) read(b[i]);
        for(int i=1;i<=n;i++) read(w[i]);

        for(int i=1;i<=n;i++){
            if(a[b[i]]<=a[i]&&a[b[i]]+w[b[i]]>a[i]){
                if(i!=b[i]){
                    add(i,b[i]);
                    add(b[i],i);
                    d[i]++;
                }else{
                    ans[i]=a[i];
                }
            }else if(a[b[i]]>a[i]){
                ans[i]=(a[i]+w[i])%Mod;
            }else{
                ans[i]=a[i];
            }
        }

        for(int i=1;i<=n;i++){
            if(!d[i]) dfs(i,0,(ans[i]==(a[i]+w[i])));
        }

        for(int i=1;i<=n;i++){
            if(d[i]) ans[i]=(a[i]+ans[i]*w[i]%Mod)%Mod;
        }
        
        for(int i=1;i<=n;i++) cout<<ans[i]<<" ";
        cout<<endl;
    }

    return 0;
}
/*

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


*/

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 22092kb

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: 140ms
memory: 22108kb

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 590444253 906393935 859123744 
863886789 
871186919 814243920 968784984 206455474 17527050 449261413 196759729 901433117 519383814 907574792 983760005 984444619 489899014 435736558 113628626 977360756 482247153 963066959 
665922935 577926775 168068923 421298438 601054667 99438820...

result:

wrong answer 27th numbers differ - expected: '132646723', found: '168068923'