QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#364303#8237. Sugar Sweet IIucup-team1525#WA 126ms15172kbC++171.3kb2024-03-24 13:37:142024-03-24 13:37:14

Judging History

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

  • [2024-11-04 16:59:03]
  • hack成功,自动添加数据
  • (/hack/1109)
  • [2024-03-24 13:37:14]
  • 评测
  • 测评结果:WA
  • 用时:126ms
  • 内存:15172kb
  • [2024-03-24 13:37:14]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=5e5;
const int mod=1e9+7;
int ksm(ll x,int tp,int s=1){
    for(;tp;x=x*x%mod,tp>>=1) if(tp&1) s=x*s%mod;
    return s;
}
int fac[N+5],ifac[N+5];
void prep(){
    fac[0]=1;
    for(int i=1;i<=N;i++) fac[i]=1ll*fac[i-1]*i%mod;
    ifac[N]=ksm(fac[N],mod-2);
    for(int i=N;i;i--) ifac[i-1]=1ll*ifac[i]*i%mod;
}
int n;
int a[N+5];
int b[N+5],w[N+5];
int len[N+5];
bool in[N+5];
int dfs(int u){
    if(len[u]!=-1) return len[u];
    if(in[u]) return -2;
    if(a[u]<a[b[u]]) return 0;
    if(a[u]>=a[b[u]]+w[b[u]]) return -2;
    in[u]=1;
    int t=dfs(b[u]);
    in[u]=0;
    if(t==-2) return -2;
    else return t+1;
}
void solve(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        len[i]=-1;
    }
    for(int i=1;i<=n;i++)
        scanf("%d",&b[i]);
    for(int i=1;i<=n;i++)
        scanf("%d",&w[i]);
    for(int i=1;i<=n;i++){
        if(len[i]==-1){
            len[i]=dfs(i);
            if(len[i]!=-2) len[i]++;
        }
        if(len[i]==-2)
            printf("%d ",a[i]);
        else
            printf("%d ",(a[i]+1ll*ifac[len[i]]*w[i])%mod);
    }
    puts("");
}
int main(){
    prep();
    int t; scanf("%d",&t);
    while(t--) solve();
    return 0;
}

详细

Test #1:

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

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: 126ms
memory: 14436kb

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 817076658 21184157 859123744 
863886789 
871186919 814243920 968784984 206455474 801864819 449261413 196759729 901433117 519383814 907574792 983760005 984444619 489899014 435736558 113628626 977360756 502171683 963066959 
665922935 577926775 132646723 421298438 601054667 99438820...

result:

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