QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#326837 | #8237. Sugar Sweet II | james1BadCreeper | WA | 1ms | 3732kb | C++14 | 1.5kb | 2024-02-14 08:49:45 | 2024-02-14 08:49:45 |
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 = fac[0] = 1; i <= n; ++i) fac[i] = 1ll * fac[i - 1] * i % P;
ifac[n] = poww(fac[n], P - 2);
for (int i = n - 1; i >= 0; --i) ifac[i] = 1ll * ifac[i + 1] * (i + 1) % P;
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 (a[i] >= a[b[i]] + w[b[i]]) f[i] = -1; // 不发生
if (a[i] < a[b[i]]) f[i] = 1;
}
for (int i = 1; i <= n; ++i) {
if (f[i] == -1) cout << a[i] << " \n"[i == n];
if (f[i] == 1) cout << a[i] + w[i] << " \n"[i == n];
if (f[i] == 0) dfs(i), cout << (a[i] + 1ll * w[i] * ifac[d[i] + 1]) % P << " \n"[i == n];
}
}
int main(void) {
ios::sync_with_stdio(0);
int T; cin >> T;
while (T--) solve();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3732kb
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 5 6 11 10 9 166666673 5 6 500000006 4 3 4 5
result:
wrong answer 2nd numbers differ - expected: '5', found: '7'