QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#324597 | #8237. Sugar Sweet II | ucup-team296# | WA | 153ms | 3816kb | C++20 | 3.5kb | 2024-02-10 21:30:53 | 2024-02-10 21:30:53 |
Judging History
answer
#include <bits/stdc++.h>
#define long long long int
#define DEBUG
using namespace std;
// @author: pashka
int mod = 1000000007;
struct mint {
int value = 0;
constexpr mint() : value() {}
mint(const long &x) {
value = normalize(x);
}
static long normalize(const long &x) {
long v = x % mod;
if (v < 0) v += mod;
return v;
}
bool operator==(const mint &x) { return value == x.value; };
mint operator+(const mint &x) { return value + x.value; };
mint operator-(const mint &x) { return value - x.value; };
mint operator*(const mint &x) { return (long) value * x.value; };
void operator+=(const mint &x) { value = normalize(value + x.value); };
void operator-=(const mint &x) { value = normalize(value - x.value); };
};
mint power(mint a, long b) {
mint res = 1;
while (b > 0) {
if (b & 1) {
res = res * a;
}
a = a * a;
b >>= 1;
}
return res;
}
mint inv(mint a) {
return power(a, mod - 2);
}
vector<mint> fact_precalc(1, 1);
vector<mint> inv_fact_precalc(1, 1);
void precalc(int n) {
fact_precalc.resize(n + 1);
fact_precalc[0] = 1;
for (int i = 1; i < fact_precalc.size(); i++) {
fact_precalc[i] = fact_precalc[i - 1] * i;
}
inv_fact_precalc.resize(n + 1);
inv_fact_precalc[n] = inv(fact_precalc[n]);
for (int i = n - 1; i >= 0; i--) {
inv_fact_precalc[i] = inv_fact_precalc[i + 1] * (i + 1);
}
}
void ensure_fact(int n) {
while (n >= fact_precalc.size()) {
fact_precalc.push_back(fact_precalc.back() * fact_precalc.size());
inv_fact_precalc.push_back(inv(fact_precalc.back()));
}
}
mint fact(int n) {
ensure_fact(n);
return fact_precalc[n];
}
mint inv_fact(int n) {
ensure_fact(n);
return inv_fact_precalc[n];
}
mint calc_c(int n, int k) {
if (n < 0 || k < 0 || k > n) {
return 0;
}
mint res = fact(n);
res = res * inv_fact(k);
res = res * inv_fact(n - k);
return res;
}
struct test {
int n;
vector<int> p;
vector<int> d;
void dfs(int i) {
d[i] = -4;
if (p[i] < 0) {
d[i] = p[i];
return;
}
int j = p[i];
if (d[j] == -3) dfs(j);
if (d[j] == -4) {
d[i] = -2;
} else {
d[i] = d[j] + 1;
}
}
void solve() {
cin >> n;
vector<int> a(n), b(n), w(n);
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) cin >> b[i], b[i]--;
for (int i = 0; i < n; i++) cin >> w[i];
p.resize(n);
for (int i = 0; i < n; i++) {
if (a[i] < a[b[i]]) {
p[i] = -1;
} else if (a[i] < a[b[i]] + w[b[i]]) {
p[i] = b[i];
} else {
p[i] = -2;
}
}
d.assign(n, -3);
for (int i = 0; i < n; i++) {
if (d[i] == -3) dfs(i);
}
for (int i = 0; i < n; i++) {
if (d[i] == -2) {
cout << mint(a[i]).value << " ";
} else {
cout << (mint(a[i]) + mint(w[i]) * inv_fact(d[i] + 2)).value << " ";
}
}
cout << "\n";
}
};
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
test().solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3816kb
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: 153ms
memory: 3516kb
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 590444253 906393935 859123744 863886789 871186919 814243920 968784984 206455474 17527050 449261413 196759729 901433117 519383814 907574792 983760005 984444619 489899014 435736558 113628626 977360756 482247153 963066959 138645134 902719894 132646723 421298438 601054667 99438820...
result:
wrong answer 25th numbers differ - expected: '665922935', found: '138645134'