#include "circuit.h"
#include<bits/stdc++.h>
using namespace std;
#define vec vector
#define int long long
const int MOD = 1'000'002'022;
const int MXN = 100'005;
int black[MXN];
int total[MXN];
int white[MXN];
vec<int32_t> par;
vec<int32_t> a;
vec<int> tree[MXN];
int n, m;
void compute(int u) {
black[u] = 0;
if(u >= n) {
total[u] = 1;
black[u] = a[u-n];
white[u] = 1 - a[u-n];
return;
}
// cerr << "PROCESSING: " << u << '\n';
total[u] = tree[u].size();
for(int v : tree[u]) {
total[u] *= total[v];
total[u] %= MOD;
}
int k = tree[u].size();
vec<vec<int>> h(k+1, vec<int>(k+1, 0));
h[0][0] = 1;
for(int i = 0; i<k; i++) {
h[i+1][k] = h[i][k] * white[tree[u][i]];
h[i+1][k] %= MOD;
for(int j = 0; j<k; j++) {
h[i+1][j] += h[i][j] * white[tree[u][i]];
h[i+1][j] %= MOD;
h[i+1][j+1] += h[i][j] * black[tree[u][i]];
h[i+1][j+1] %= MOD;
}
}
for(int i = 0; i<=k; i++) {
black[u] += h[k][i]*i;
black[u] %= MOD;
}
white[u] = total[u] + MOD - black[u];
white[u] %= MOD;
}
void dfs1(int u = 0) {
for(int v : tree[u]) {
dfs1(v);
}
compute(u);
// cerr << "BLACK: " << black[u] << " WHITE: " << white[u] << '\n';
}
void init(int32_t N, int32_t M, std::vector<int32_t> P, std::vector<int32_t> A) {
n = N;
m = M;
a = A;
par = P;
for(int i = 1; i<N+M; i++) {
tree[P[i]].push_back(i);
}
}
int32_t count_ways(int32_t L, int32_t R) {
if(false && L == R) {
a[L] = 1-a[L];
int cur = L;
while(cur != -1) {
compute(cur);
cur = par[cur];
}
}
else {
for(int i = L; i<=R; i++) {
a[i-n] = 1-a[i-n];
}
dfs1();
}
return black[0];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
1 ms |
4696 KB |
Output is correct |
3 |
Correct |
27 ms |
12120 KB |
Output is correct |
4 |
Correct |
26 ms |
12680 KB |
Output is correct |
5 |
Correct |
35 ms |
12644 KB |
Output is correct |
6 |
Correct |
31 ms |
12668 KB |
Output is correct |
7 |
Correct |
35 ms |
12580 KB |
Output is correct |
8 |
Correct |
28 ms |
12668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
2 ms |
4696 KB |
Output is correct |
3 |
Correct |
1 ms |
4696 KB |
Output is correct |
4 |
Correct |
1 ms |
4696 KB |
Output is correct |
5 |
Correct |
1 ms |
4696 KB |
Output is correct |
6 |
Correct |
2 ms |
4696 KB |
Output is correct |
7 |
Correct |
2 ms |
4696 KB |
Output is correct |
8 |
Correct |
1 ms |
4696 KB |
Output is correct |
9 |
Correct |
1 ms |
4696 KB |
Output is correct |
10 |
Correct |
1 ms |
4696 KB |
Output is correct |
11 |
Correct |
2 ms |
4696 KB |
Output is correct |
12 |
Correct |
2 ms |
4696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
1 ms |
4696 KB |
Output is correct |
3 |
Correct |
27 ms |
12120 KB |
Output is correct |
4 |
Correct |
26 ms |
12680 KB |
Output is correct |
5 |
Correct |
35 ms |
12644 KB |
Output is correct |
6 |
Correct |
31 ms |
12668 KB |
Output is correct |
7 |
Correct |
35 ms |
12580 KB |
Output is correct |
8 |
Correct |
28 ms |
12668 KB |
Output is correct |
9 |
Correct |
1 ms |
4696 KB |
Output is correct |
10 |
Correct |
2 ms |
4696 KB |
Output is correct |
11 |
Correct |
1 ms |
4696 KB |
Output is correct |
12 |
Correct |
1 ms |
4696 KB |
Output is correct |
13 |
Correct |
1 ms |
4696 KB |
Output is correct |
14 |
Correct |
2 ms |
4696 KB |
Output is correct |
15 |
Correct |
2 ms |
4696 KB |
Output is correct |
16 |
Correct |
1 ms |
4696 KB |
Output is correct |
17 |
Correct |
1 ms |
4696 KB |
Output is correct |
18 |
Correct |
1 ms |
4696 KB |
Output is correct |
19 |
Correct |
2 ms |
4696 KB |
Output is correct |
20 |
Correct |
2 ms |
4696 KB |
Output is correct |
21 |
Correct |
1 ms |
4696 KB |
Output is correct |
22 |
Correct |
3 ms |
4696 KB |
Output is correct |
23 |
Correct |
2 ms |
4696 KB |
Output is correct |
24 |
Correct |
3 ms |
4696 KB |
Output is correct |
25 |
Correct |
2 ms |
4696 KB |
Output is correct |
26 |
Correct |
2 ms |
4696 KB |
Output is correct |
27 |
Correct |
2 ms |
4696 KB |
Output is correct |
28 |
Correct |
2 ms |
4704 KB |
Output is correct |
29 |
Correct |
32 ms |
12580 KB |
Output is correct |
30 |
Correct |
32 ms |
12580 KB |
Output is correct |
31 |
Correct |
2 ms |
4696 KB |
Output is correct |
32 |
Correct |
3 ms |
4696 KB |
Output is correct |
33 |
Correct |
2 ms |
4696 KB |
Output is correct |
34 |
Correct |
1 ms |
4696 KB |
Output is correct |
35 |
Correct |
7 ms |
5208 KB |
Output is correct |
36 |
Correct |
2 ms |
4696 KB |
Output is correct |
37 |
Correct |
36 ms |
12696 KB |
Output is correct |
38 |
Correct |
37 ms |
12684 KB |
Output is correct |
39 |
Correct |
1 ms |
4696 KB |
Output is correct |
40 |
Correct |
2 ms |
4696 KB |
Output is correct |
41 |
Correct |
2 ms |
4696 KB |
Output is correct |
42 |
Correct |
2 ms |
4696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3004 ms |
6744 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3004 ms |
6744 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
2 ms |
4696 KB |
Output is correct |
3 |
Correct |
1 ms |
4696 KB |
Output is correct |
4 |
Correct |
1 ms |
4696 KB |
Output is correct |
5 |
Correct |
1 ms |
4696 KB |
Output is correct |
6 |
Correct |
2 ms |
4696 KB |
Output is correct |
7 |
Correct |
2 ms |
4696 KB |
Output is correct |
8 |
Correct |
1 ms |
4696 KB |
Output is correct |
9 |
Correct |
1 ms |
4696 KB |
Output is correct |
10 |
Correct |
1 ms |
4696 KB |
Output is correct |
11 |
Correct |
2 ms |
4696 KB |
Output is correct |
12 |
Correct |
2 ms |
4696 KB |
Output is correct |
13 |
Execution timed out |
3004 ms |
6744 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
1 ms |
4696 KB |
Output is correct |
3 |
Correct |
27 ms |
12120 KB |
Output is correct |
4 |
Correct |
26 ms |
12680 KB |
Output is correct |
5 |
Correct |
35 ms |
12644 KB |
Output is correct |
6 |
Correct |
31 ms |
12668 KB |
Output is correct |
7 |
Correct |
35 ms |
12580 KB |
Output is correct |
8 |
Correct |
28 ms |
12668 KB |
Output is correct |
9 |
Correct |
1 ms |
4696 KB |
Output is correct |
10 |
Correct |
2 ms |
4696 KB |
Output is correct |
11 |
Correct |
1 ms |
4696 KB |
Output is correct |
12 |
Correct |
1 ms |
4696 KB |
Output is correct |
13 |
Correct |
1 ms |
4696 KB |
Output is correct |
14 |
Correct |
2 ms |
4696 KB |
Output is correct |
15 |
Correct |
2 ms |
4696 KB |
Output is correct |
16 |
Correct |
1 ms |
4696 KB |
Output is correct |
17 |
Correct |
1 ms |
4696 KB |
Output is correct |
18 |
Correct |
1 ms |
4696 KB |
Output is correct |
19 |
Correct |
2 ms |
4696 KB |
Output is correct |
20 |
Correct |
2 ms |
4696 KB |
Output is correct |
21 |
Correct |
1 ms |
4696 KB |
Output is correct |
22 |
Correct |
3 ms |
4696 KB |
Output is correct |
23 |
Correct |
2 ms |
4696 KB |
Output is correct |
24 |
Correct |
3 ms |
4696 KB |
Output is correct |
25 |
Correct |
2 ms |
4696 KB |
Output is correct |
26 |
Correct |
2 ms |
4696 KB |
Output is correct |
27 |
Correct |
2 ms |
4696 KB |
Output is correct |
28 |
Correct |
2 ms |
4704 KB |
Output is correct |
29 |
Correct |
32 ms |
12580 KB |
Output is correct |
30 |
Correct |
32 ms |
12580 KB |
Output is correct |
31 |
Correct |
2 ms |
4696 KB |
Output is correct |
32 |
Correct |
3 ms |
4696 KB |
Output is correct |
33 |
Correct |
2 ms |
4696 KB |
Output is correct |
34 |
Correct |
1 ms |
4696 KB |
Output is correct |
35 |
Correct |
7 ms |
5208 KB |
Output is correct |
36 |
Correct |
2 ms |
4696 KB |
Output is correct |
37 |
Correct |
36 ms |
12696 KB |
Output is correct |
38 |
Correct |
37 ms |
12684 KB |
Output is correct |
39 |
Correct |
1 ms |
4696 KB |
Output is correct |
40 |
Correct |
2 ms |
4696 KB |
Output is correct |
41 |
Correct |
2 ms |
4696 KB |
Output is correct |
42 |
Correct |
2 ms |
4696 KB |
Output is correct |
43 |
Execution timed out |
3019 ms |
4696 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
1 ms |
4696 KB |
Output is correct |
3 |
Correct |
27 ms |
12120 KB |
Output is correct |
4 |
Correct |
26 ms |
12680 KB |
Output is correct |
5 |
Correct |
35 ms |
12644 KB |
Output is correct |
6 |
Correct |
31 ms |
12668 KB |
Output is correct |
7 |
Correct |
35 ms |
12580 KB |
Output is correct |
8 |
Correct |
28 ms |
12668 KB |
Output is correct |
9 |
Correct |
1 ms |
4696 KB |
Output is correct |
10 |
Correct |
2 ms |
4696 KB |
Output is correct |
11 |
Correct |
1 ms |
4696 KB |
Output is correct |
12 |
Correct |
1 ms |
4696 KB |
Output is correct |
13 |
Correct |
1 ms |
4696 KB |
Output is correct |
14 |
Correct |
2 ms |
4696 KB |
Output is correct |
15 |
Correct |
2 ms |
4696 KB |
Output is correct |
16 |
Correct |
1 ms |
4696 KB |
Output is correct |
17 |
Correct |
1 ms |
4696 KB |
Output is correct |
18 |
Correct |
1 ms |
4696 KB |
Output is correct |
19 |
Correct |
2 ms |
4696 KB |
Output is correct |
20 |
Correct |
2 ms |
4696 KB |
Output is correct |
21 |
Correct |
1 ms |
4696 KB |
Output is correct |
22 |
Correct |
3 ms |
4696 KB |
Output is correct |
23 |
Correct |
2 ms |
4696 KB |
Output is correct |
24 |
Correct |
3 ms |
4696 KB |
Output is correct |
25 |
Correct |
2 ms |
4696 KB |
Output is correct |
26 |
Correct |
2 ms |
4696 KB |
Output is correct |
27 |
Correct |
2 ms |
4696 KB |
Output is correct |
28 |
Correct |
2 ms |
4704 KB |
Output is correct |
29 |
Correct |
32 ms |
12580 KB |
Output is correct |
30 |
Correct |
32 ms |
12580 KB |
Output is correct |
31 |
Correct |
2 ms |
4696 KB |
Output is correct |
32 |
Correct |
3 ms |
4696 KB |
Output is correct |
33 |
Correct |
2 ms |
4696 KB |
Output is correct |
34 |
Correct |
1 ms |
4696 KB |
Output is correct |
35 |
Correct |
7 ms |
5208 KB |
Output is correct |
36 |
Correct |
2 ms |
4696 KB |
Output is correct |
37 |
Correct |
36 ms |
12696 KB |
Output is correct |
38 |
Correct |
37 ms |
12684 KB |
Output is correct |
39 |
Correct |
1 ms |
4696 KB |
Output is correct |
40 |
Correct |
2 ms |
4696 KB |
Output is correct |
41 |
Correct |
2 ms |
4696 KB |
Output is correct |
42 |
Correct |
2 ms |
4696 KB |
Output is correct |
43 |
Execution timed out |
3004 ms |
6744 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |