#include <iostream>
#include <vector>
using i64 = int64_t;
int n, m;
std::vector<int> p, a;
std::vector<std::vector<int>> children;
const i64 MOD = 1'000'002'022;
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
n = N;
m = M;
p = P;
a = A;
children.resize(N);
for (i64 i = 1; i < N + M; i++) {
children[P[i]].push_back(i);
}
}
auto dfs(int node) -> std::pair<i64, i64> {
if (node >= n) {
return {a[node - n] ? 1 : 0, 1};
}
i64 cs = children[node].size();
std::vector<std::pair<i64, i64>> results;
results.reserve(cs);
for (i64 c : children[node]) {
results.push_back(dfs(c));
}
std::vector<i64> xs_left {1}, xs_right {1};
xs_left.reserve(cs);
xs_right.reserve(cs);
for (i64 i = 0; i < cs; i++) {
xs_left.push_back(xs_left.back() * results[i].second % MOD);
xs_right.push_back(xs_right.back() * results[cs - i - 1].second % MOD);
}
i64 sum = 0, of = cs;
for (i64 i = 0; i < cs; i++) {
sum += results[i].first * xs_left[i] % MOD * xs_right[n - i - 1];
cs *= results[i].second;
}
return {sum, of};
}
int count_ways(int l, int r) {
r += 1;
l -= n;
r -= n;
for (i64 i = l; i < r; i++) {
a[i] = !a[i];
}
return dfs(0).first;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
2nd lines differ - on the 1st token, expected: '2', found: '50' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
2nd lines differ - on the 1st token, expected: '2', found: '50' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
2nd lines differ - on the 1st token, expected: '2', found: '50' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
12 ms |
5540 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
12 ms |
5540 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
2nd lines differ - on the 1st token, expected: '2', found: '50' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
2nd lines differ - on the 1st token, expected: '2', found: '50' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
2nd lines differ - on the 1st token, expected: '2', found: '50' |
2 |
Halted |
0 ms |
0 KB |
- |