QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#326844 | #8237. Sugar Sweet II | james1BadCreeper | WA | 3ms | 7504kb | C++14 | 1.4kb | 2024-02-14 09:03:34 | 2024-02-14 09:03:35 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int P = 1e9 + 7;
const int N = 5e5 + 5;
inline int poww(int a, int b) {
int r = 1;
for (; b; b >>= 1, a = 1ll * a * a % P)
if (b & 1) r = 1ll * r * a % P;
return r;
}
int n, a[N], b[N], w[N], f[N], d[N], vis[N];
int fac[N], ifac[N];
void dfs(int x) {
if (f[x] || d[x]) return;
if (vis[x]) return f[x] = -1, void();
vis[x] = 1; dfs(b[x]); vis[x] = 0;
if (f[b[x]] == -1) f[x] = -1;
else d[x] = d[b[x]] + 1;
}
void solve(void) {
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i], d[i] = vis[i] = 0;
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) {
f[i] = 0;
if (i == b[i] || a[i] >= a[b[i]] + w[b[i]]) f[i] = -1; // 不发生
if (a[i] < a[b[i]]) f[i] = 1;
}
// 2 5 5 2
// 4 2 1 3
for (int i = 1; i <= n; ++i) {
dfs(i);
cout << (a[i] + 1ll * w[i] * ifac[d[i] + 1]) % P << " \n"[i == n];
}
}
int main(void) {
for (int i = fac[0] = 1; i < N; ++i) fac[i] = 1ll * fac[i - 1] * i % P;
ifac[N - 1] = poww(fac[N - 1], P - 2);
for (int i = N - 2; i >= 0; --i) ifac[i] = 1ll * ifac[i + 1] * (i + 1) % P;
ios::sync_with_stdio(0); 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: 3ms
memory: 7504kb
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 7 6 6 11 10 9 166666673 5 6 500000006 4 7 4 5
result:
wrong answer 2nd numbers differ - expected: '5', found: '7'