QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#574193 | #8237. Sugar Sweet II | zrzring | WA | 123ms | 3928kb | C++20 | 1.8kb | 2024-09-18 21:03:03 | 2024-09-18 21:03:04 |
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 (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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
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:
500000007 5 5 6 5 10 9 166666673 5 6 500000006 4 3 4 5
result:
ok 15 numbers
Test #2:
score: -100
Wrong Answer
time: 123ms
memory: 3928kb
input:
50000 5 508432375 168140163 892620793 578579275 251380640 3 4 4 1 3 346232959 736203130 186940774 655629320 607743104 1 863886789 1 364158084 18 864679185 463975750 558804051 604216585 694033700 499417132 375390750 337590759 467353355 111206671 983760005 984444619 322277587 138763925 205122047 97736...
output:
854665334 904343293 892620793 578579275 859123744 863886789 871186919 814243920 968784984 206455474 694033700 449261413 196759729 901433117 519383814 907574792 983760005 984444619 489899014 435736558 113628626 977360756 512133948 963066959 665922935 577926775 132646723 421298438 601054667 99438820 3...
result:
wrong answer 3rd numbers differ - expected: '590444253', found: '892620793'