QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#734412 | #8237. Sugar Sweet II | WorldFinalEscaped | WA | 64ms | 17996kb | C++14 | 1.4kb | 2024-11-11 10:05:50 | 2024-11-11 10:05:50 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=5e5+5,mod=1e9+7;
int a[N],b[N],w[N],sta[N],vis[N],dep[N],fac[N],Inv[N];
int T,n;
inline int fastpow(int x, int y){
int z=1;
for (; y; y>>=1,x=1ll*x*x%mod)
if (y&1) z=1ll*z*x%mod;
return z;
}
void dfs(int u){
if (vis[u]) return;
// printf("======>%d\n",u);
vis[u]=1;
if (sta[u]==1) return;
dfs(b[u]);
sta[u]=sta[b[u]];
dep[u]=dep[b[u]]+1;
}
int main(){
fac[0]=Inv[0]=1;
for (int i=1; i<=500000; i++) Inv[i]=fastpow(fac[i]=1ll*fac[i-1]*i%mod,mod-2);
for (cin>>T; T; T--){
scanf("%d",&n);
for (int i=1; i<=n; i++) scanf("%d",&a[i]);
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++){
sta[i]=0; vis[i]=dep[i]=0;
if (a[i]<a[b[i]]) sta[i]=1,dep[i]=1;//printf("==>%d\n",i);
}
for (int i=1; i<=n; i++)
if (!vis[i]) dfs(i);//puts("");
// for (int i=1; i<=n; i++) printf("-->%d %d\n",sta[i],dep[i]);
for (int i=1; i<=n; i++)
if (!sta[i]) printf("%d ",a[i]);
else printf("%d ",(a[i]+1ll*w[i]*Inv[dep[i]])%mod);
puts("");
}
}
/*
1
5
508432375 168140163 892620793 578579275 251380640
3 4 4 1 3
346232959 736203130 186940774 655629320 607743104
*/
详细
Test #1:
score: 0
Wrong Answer
time: 64ms
memory: 17996kb
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 166666673 6 5 10 9 166666673 5 6 500000006 4 666666675 4 5
result:
wrong answer 3rd numbers differ - expected: '5', found: '166666673'