QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#587626 | #8237. Sugar Sweet II | SLF666 | WA | 3ms | 34300kb | C++17 | 2.0kb | 2024-09-24 20:53:07 | 2024-09-24 20:53:07 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define endl "\n"
const int N = 5e5 + 5;
const ll mod = 1e9 + 7;
ll ksm(ll x,ll y){
ll res = 1;
while(y){
if(y & 1)res = res * x % mod;
y >>= 1;
x = x * x % mod;
}
return res;
}
int p[N], d[N];
int find(int x){
if(p[x] != x){
int temp = p[x];
p[x] = find(p[x]);
d[x] += d[temp];
}
return p[x];
}
ll fac[N], inv[N], ans[N], a[N], b[N], w[N];
vector<int>g[N];
int vis[N];
void dfs(int u,int fa,int dep){
if(dep){
ans[u] = (a[u] + 1ll * w[u] * inv[dep + 1] % mod) % mod;
}
for(auto &v:g[u]){
if(v == fa)continue;
if(!vis[v])dfs(v, u, dep + 1);
}
}
void solve(){
int n;
cin>>n;
// vector<ll>a(n+1), b(n+1), w(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++){
p[i] = i;
d[i] = 0;
ans[i] = vis[i] = 0;
vector<int>().swap(g[i]);
}
// vector<int>vis(n+1);
for(int i=1;i<=n;i++){
if(a[i] >= a[b[i]] + w[b[i]]){
vis[i] = 2;
}
else if(a[i] < a[b[i]]){
vis[i] = 1;
ans[i] = a[i] + w[i];
}
int u = i, v = b[i];
g[u].push_back(v);
g[v].push_back(u);
}
for(int i=1;i<=n;i++){
if(vis[i] == 1)dfs(i, 0, 0);
}
// for(int i=1;i<=n;i++){
// if(vis[i])continue;
// int pi = find(i);
// if(vis[pi] != 1){
// continue;
// }
// int dis = d[i];
// ans[i] = (a[i] + 1ll * w[i] * inv[dis + 1] % mod) % mod;
// }
// for(int i = 1; i <=n ; i ++)cout << p[i] <<endl;
for(int i=1;i<=n;i++){
if(!ans[i])ans[i] = a[i];
cout<<ans[i]<<" ";
}
cout<<endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t = 1;
fac[0] = inv[0] = 1;
for(int i=1;i<N;i++){
fac[i] = 1ll * fac[i - 1] * i % mod;
}
inv[N - 1] = ksm(fac[N - 1], mod - 2);
for(int i=N-2;i>=1;i--)inv[i] = inv[i + 1] * (i + 1) % mod;
cin>>t;
for(int i=1;i<=t;i++)solve();
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 34300kb
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 6 10 9 500000009 333333340 6 500000006 4 3 4 5
result:
wrong answer 5th numbers differ - expected: '5', found: '6'