#include <bits/stdc++.h>
using namespace std;
#define int long long
int n, M;
vector<int> p, a;
vector<vector<int>> ch;
vector<int> conv(vector<signed> v) {
vector<int> ans(n);
for (int i = 0; i < n; i++) ans[i] = v[i];
return ans;
}
void init(signed n_, signed M_, vector<signed> p_, vector<signed> a_) {
n = n_, M = M_, p = conv(p_), a = conv(a_);
ch.resize(n + M);
for (int i = 1; i < n + M; i++) {
ch[p[i]].push_back(i);
}
}
int count_ways(signed l, signed r) {
for (int i = l - n; i <= r - n; i++) {
a[i] = !a[i];
}
vector<int> on(n + M), off(n + M);
for (int i = n; i < n + M; i++) {
if (a[i]) on[i] = 1;
else off[i] = 1;
}
for (int i = n - 1; i >= 0; i--) {
if (ch[i].size() == 1) {
on[i] = on[ch[i][0]];
off[i] = off[ch[i][0]];
} else {
int x1 = on[ch[i][0]], y1 = off[ch[i][0]], x2 = on[ch[i][1]], y2 = off[ch[i][1]];
on[i] = (2 * x1 * x2 + x1 * y2 + y1 * x2) % 1000002022;
off[i] = (2 * y1 * y2 + x1 * y2 + y1 * x2) % 1000002022;
}
}
return on[0];
}
#ifdef ONLINE_JUDGE
signed main() {
init(1, 2, {0, 0}, {1, 1});
count_ways(0, 0);
count_ways(0, 0);
}
#endif
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
9 ms |
7376 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
9 ms |
7376 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |