QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#574199 | #8237. Sugar Sweet II | zrzring | WA | 0ms | 3648kb | C++20 | 1.9kb | 2024-09-18 21:04:35 | 2024-09-18 21:04:35 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
using A2 = std::array<i64, 2>;
#define Fast_IOS std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0)
const i64 mod = 1e9 + 7;
template <class T>
T MOD(T& x, i64 p = mod) {
return x = (x % p + p) % p;
}
template <class T>
T MOD(T&& x, i64 p = mod) {
return x = (x % p + p) % p;
}
i64 qpow(i64 a, i64 x = mod - 2) {
a %= mod;
x %= mod - 1;
i64 res = 1;
while (x) {
if (x & 1) res = res * a % mod;
a = a * a % mod;
x >>= 1;
}
return res;
}
class WORK {
public:
int N;
WORK() {}
void solve() {
int n;
std::cin >> n;
std::vector<i64> a(n + 1), to(n + 1), b(n + 1), fac(n + 1), ifac(n + 1);
for (int i = 1; i <= n; i++) {
std::cin >> a[i];
}
for (int i = 1; i <= n; i++) {
std::cin >> to[i];
}
for (int i = 1; i <= n; i++) {
std::cin >> b[i];
}
fac[0] = 1;
for (int i = 1; i <= n; i++) {
fac[i] = fac[i - 1] * i % mod;
}
ifac[n] = qpow(fac[n]);
for (int i = n - 1; i >= 0; i--) {
ifac[i] = ifac[i + 1] * (i + 1) % mod;
}
std::vector<i64> dep(n + 1), vis(n + 1);
auto dfs = [&](auto self, int u) -> void {
vis[u] = 1;
int v = to[u];
if (a[u] < a[v]) {
dep[u] = 1;
return;
}
if (dep[v]) {
dep[u] = dep[v] + 1;
return;
}
if (to[u] == u || a[u] >= a[v] + b[v] || vis[v]) {
dep[u] = -1;
return;
}
self(self, v);
if (dep[v] == -1) dep[u] = -1;
else dep[u] = dep[v] + 1;
};
for (int i = 1; i <= n; i++) {
if (!dep[i]) dfs(dfs, i);
}
for (int i = 1; i <= n; i++) {
if (dep[i] == -1) {
std::cout << a[i] << " \n"[i == n];
} else {
std::cout << (a[i] + b[i] * ifac[dep[i]]) % mod << " \n"[i == n];
}
}
}
};
int main() {
Fast_IOS;
WORK work;
int T = 1;
std::cin >> T;
while (T--) {
work.solve();
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3648kb
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 5 166666673 6 5 10 9 166666673 5 6 500000006 4 666666675 4 5
result:
wrong answer 3rd numbers differ - expected: '5', found: '166666673'