QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#679578#8237. Sugar Sweet IItsogsummitWA 54ms20640kbC++142.0kb2024-10-26 17:55:202024-10-26 17:55:21

Judging History

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

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

answer

#include<bits/stdc++.h>
using namespace std;

using ll = long long;

const int mod = 1e9 + 7;
const int N = 5e5 + 5;

ll fac[N], inv[N];
bool vis[N];
int d[N];
int par[N], a[N], w[N], b[N];

ll binpow(ll a, ll b, ll mod){
    ll res = 1;
    while(b){
        if(b & 1)
            res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

ll mul(ll a, ll b){
    a %= mod;
    b %= mod;
    return a * b % mod;
}
ll sub(ll a, ll b){
    a -= b;
    while(a < 0) a += mod;
    return a;
}
ll add(ll a, ll b){
    a += b;
    return a % mod;
}
void init(int n){
    for(int i = 0; i < n;   i++){
        vis[i] = false;
        d[i] = 0;
        par[i] = -1;
    }
}

int solve(int i){
    if(par[i] == -1)return 0;
    if(a[i] < a[b[i]])return 1;
    if(vis[i])return d[i];
    vis[i] = true;
    d[i] = 1 + solve(par[i]);

    return d[i];
}

void solve(){
    int n;
    cin >> n;
    init(n);
    
    vector<int> ans(n, -1);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n; i++){
        cin >> b[i]; b[i]--;
        par[i] = b[i];
    }
    for(int i = 0; i < n; i++){
        cin >> w[i];
    }

    for(int i = 0; i < n; i++){
        if(a[i] >= a[b[i]] + w[b[i]] || i == b[i]){
            ans[i] = a[i];
            continue;
        }
        if(a[i] < a[b[i]]){
            ans[i] = (a[i] + w[i]) % mod;
            continue;
        }
    }
    for(int i = 0; i < n; i++){
        solve(i);
    }
    for(int i = 0; i < n; i++){
        if(ans[i] == -1){
            ans[i] = add(mul(inv[d[i] + 1], a[i] + w[i]), mul(sub(1, inv[d[i] + 1]), a[i]));
        }
    }
    for(int i = 0; i < n; i++){
        cout << ans[i] << " \n"[i == n - 1];
    }
}
int main() {
    int t;
    cin >> t;
    fac[0] = 1;
    for(int i = 1; i < N; i++){
        fac[i] = (fac[i - 1] * i) % mod;
        inv[i] = binpow(fac[i], mod - 2, mod);
    }
    while(t--){
        solve();
    }
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 54ms
memory: 20640kb

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:

500000006 5 5 6
5 10 9
41666672 333333340 6
166666670 4 3 4 5

result:

wrong answer 1st numbers differ - expected: '500000007', found: '500000006'