QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#634997 | #8237. Sugar Sweet II | cy325 | WA | 0ms | 3796kb | C++20 | 1.5kb | 2024-10-12 18:41:10 | 2024-10-12 18:41:10 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;
// 快速幂计算 x^y % MOD
ll power_mod(ll x, ll y, ll mod) {
ll res = 1;
x %= mod;
while(y > 0){
if(y & 1) res = res * x % mod;
x = x * x % mod;
y >>= 1;
}
return res;
}
struct child{
ll a;
ll b;
ll w;
};
void solve(){
int n;
cin >> n;
vector<child> v(n+1);
for(int i=1;i<=n;i++) cin >> v[i].a;
for(int i=1;i<=n;i++) cin >> v[i].b;
for(int i=1;i<=n;i++) cin >> v[i].w;
// 初始化期望值为初始糖果数量
vector<long long> expectation(n+1, 0);
for(int i=1;i<=n;i++) expectation[i] = v[i].a;
// 计算每个事件的贡献
for(int i=1;i<=n;i++){
int bi = v[i].b;
if(v[i].a < v[bi].a){
// 事件 i 有 50% 的概率触发
// 期望增量为 w[i] / 2
// 计算 w[i] * inv(2) % MOD
ll inv2 = power_mod(2, MOD-2, MOD);
ll contribution = (v[i].w * inv2) % MOD;
expectation[i] = (expectation[i] + contribution) % MOD;
}
// 如果 a[i] >= a[bi],事件不会触发,无需更新
}
// 输出结果
for(int i=1;i<=n;i++){
cout << expectation[i] << (i==n ? '\n' : ' ');
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while(t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3796kb
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:
2 5 5 4 5 7 6 5 4 500000008 2 500000006 3 3 3
result:
wrong answer 1st numbers differ - expected: '500000007', found: '2'