QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#678824#8237. Sugar Sweet IItsogsummitCompile Error//C++141.9kb2024-10-26 16:13:552024-10-26 16:13:56

Judging History

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

  • [2024-11-04 16:59:03]
  • hack成功,自动添加数据
  • (/hack/1109)
  • [2024-10-26 16:13:56]
  • 评测
  • [2024-10-26 16:13:55]
  • 提交

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];

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;
    if(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;
    }

    order.clear();
}

int solve(int i){
    if(par[i] == -1)return 0;
    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> a(n), b(n), w(n), ans(n);
    for(auto &x: a)cin>>x;
    for(int i = 0; i < n; i++){
        cin >> b[i]; b[i]--;
    }
    for(auto &x: w)cin>>x;
    for(int i = 0; i < n; i++){
        if(a[i] >= a[b[i]] + w[b[i]] || i == b[i]){
            ans[i] = a[i] % mod;
            continue;
        }
        if(a[i] < a[b[i]]){
            ans[i] = (a[i] + w[i]) % mod;
            continue;
        }
        par[i] = b[i];
    }
    for(int i = 0; i < n; i++){
        solve(i);
    }
    
    for(int i = 0; i < n; i++){
        if(!ans[i]){
            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();
    }
}

Details

answer.code: In function ‘void init(int)’:
answer.code:46:5: error: ‘order’ was not declared in this scope
   46 |     order.clear();
      |     ^~~~~