#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;
// cerr << "BLACK: " << black[u] << " WHITE: " << white[u] << '\n';
}
void dfs1(int u = 0) {
for(int v : tree[u]) {
dfs1(v);
}
compute(u);
}
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);
}
dfs1();
}
int32_t count_ways(int32_t L, int32_t R) {
if( L == R) {
a[L-n] = 1-a[L-n];
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 |
2648 KB |
Output is correct |
3 |
Correct |
39 ms |
10440 KB |
Output is correct |
4 |
Correct |
34 ms |
12644 KB |
Output is correct |
5 |
Correct |
38 ms |
12676 KB |
Output is correct |
6 |
Correct |
41 ms |
12584 KB |
Output is correct |
7 |
Correct |
35 ms |
12632 KB |
Output is correct |
8 |
Correct |
47 ms |
12672 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 |
1 ms |
4696 KB |
Output is correct |
4 |
Correct |
2 ms |
4696 KB |
Output is correct |
5 |
Correct |
2 ms |
4696 KB |
Output is correct |
6 |
Correct |
1 ms |
4696 KB |
Output is correct |
7 |
Correct |
2 ms |
4696 KB |
Output is correct |
8 |
Correct |
3 ms |
4696 KB |
Output is correct |
9 |
Correct |
2 ms |
4696 KB |
Output is correct |
10 |
Correct |
2 ms |
4696 KB |
Output is correct |
11 |
Correct |
2 ms |
4696 KB |
Output is correct |
12 |
Correct |
1 ms |
4696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Correct |
39 ms |
10440 KB |
Output is correct |
4 |
Correct |
34 ms |
12644 KB |
Output is correct |
5 |
Correct |
38 ms |
12676 KB |
Output is correct |
6 |
Correct |
41 ms |
12584 KB |
Output is correct |
7 |
Correct |
35 ms |
12632 KB |
Output is correct |
8 |
Correct |
47 ms |
12672 KB |
Output is correct |
9 |
Correct |
1 ms |
4696 KB |
Output is correct |
10 |
Correct |
1 ms |
4696 KB |
Output is correct |
11 |
Correct |
1 ms |
4696 KB |
Output is correct |
12 |
Correct |
2 ms |
4696 KB |
Output is correct |
13 |
Correct |
2 ms |
4696 KB |
Output is correct |
14 |
Correct |
1 ms |
4696 KB |
Output is correct |
15 |
Correct |
2 ms |
4696 KB |
Output is correct |
16 |
Correct |
3 ms |
4696 KB |
Output is correct |
17 |
Correct |
2 ms |
4696 KB |
Output is correct |
18 |
Correct |
2 ms |
4696 KB |
Output is correct |
19 |
Correct |
2 ms |
4696 KB |
Output is correct |
20 |
Correct |
1 ms |
4696 KB |
Output is correct |
21 |
Correct |
4 ms |
4696 KB |
Output is correct |
22 |
Correct |
3 ms |
4708 KB |
Output is correct |
23 |
Correct |
2 ms |
4696 KB |
Output is correct |
24 |
Correct |
2 ms |
4948 KB |
Output is correct |
25 |
Correct |
3 ms |
4696 KB |
Output is correct |
26 |
Correct |
3 ms |
2904 KB |
Output is correct |
27 |
Correct |
3 ms |
4696 KB |
Output is correct |
28 |
Correct |
3 ms |
2904 KB |
Output is correct |
29 |
Correct |
42 ms |
12672 KB |
Output is correct |
30 |
Correct |
42 ms |
12796 KB |
Output is correct |
31 |
Correct |
3 ms |
4692 KB |
Output is correct |
32 |
Correct |
2 ms |
4696 KB |
Output is correct |
33 |
Correct |
2 ms |
4696 KB |
Output is correct |
34 |
Correct |
2 ms |
4696 KB |
Output is correct |
35 |
Correct |
11 ms |
5152 KB |
Output is correct |
36 |
Correct |
3 ms |
4696 KB |
Output is correct |
37 |
Correct |
50 ms |
12732 KB |
Output is correct |
38 |
Correct |
54 ms |
10848 KB |
Output is correct |
39 |
Correct |
2 ms |
4696 KB |
Output is correct |
40 |
Correct |
3 ms |
2648 KB |
Output is correct |
41 |
Correct |
2 ms |
2648 KB |
Output is correct |
42 |
Correct |
4 ms |
4696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
749 ms |
7000 KB |
Output is correct |
2 |
Runtime error |
47 ms |
18708 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
749 ms |
7000 KB |
Output is correct |
2 |
Runtime error |
47 ms |
18708 KB |
Execution killed with signal 11 |
3 |
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 |
1 ms |
4696 KB |
Output is correct |
4 |
Correct |
2 ms |
4696 KB |
Output is correct |
5 |
Correct |
2 ms |
4696 KB |
Output is correct |
6 |
Correct |
1 ms |
4696 KB |
Output is correct |
7 |
Correct |
2 ms |
4696 KB |
Output is correct |
8 |
Correct |
3 ms |
4696 KB |
Output is correct |
9 |
Correct |
2 ms |
4696 KB |
Output is correct |
10 |
Correct |
2 ms |
4696 KB |
Output is correct |
11 |
Correct |
2 ms |
4696 KB |
Output is correct |
12 |
Correct |
1 ms |
4696 KB |
Output is correct |
13 |
Correct |
749 ms |
7000 KB |
Output is correct |
14 |
Runtime error |
47 ms |
18708 KB |
Execution killed with signal 11 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Correct |
39 ms |
10440 KB |
Output is correct |
4 |
Correct |
34 ms |
12644 KB |
Output is correct |
5 |
Correct |
38 ms |
12676 KB |
Output is correct |
6 |
Correct |
41 ms |
12584 KB |
Output is correct |
7 |
Correct |
35 ms |
12632 KB |
Output is correct |
8 |
Correct |
47 ms |
12672 KB |
Output is correct |
9 |
Correct |
1 ms |
4696 KB |
Output is correct |
10 |
Correct |
1 ms |
4696 KB |
Output is correct |
11 |
Correct |
1 ms |
4696 KB |
Output is correct |
12 |
Correct |
2 ms |
4696 KB |
Output is correct |
13 |
Correct |
2 ms |
4696 KB |
Output is correct |
14 |
Correct |
1 ms |
4696 KB |
Output is correct |
15 |
Correct |
2 ms |
4696 KB |
Output is correct |
16 |
Correct |
3 ms |
4696 KB |
Output is correct |
17 |
Correct |
2 ms |
4696 KB |
Output is correct |
18 |
Correct |
2 ms |
4696 KB |
Output is correct |
19 |
Correct |
2 ms |
4696 KB |
Output is correct |
20 |
Correct |
1 ms |
4696 KB |
Output is correct |
21 |
Correct |
4 ms |
4696 KB |
Output is correct |
22 |
Correct |
3 ms |
4708 KB |
Output is correct |
23 |
Correct |
2 ms |
4696 KB |
Output is correct |
24 |
Correct |
2 ms |
4948 KB |
Output is correct |
25 |
Correct |
3 ms |
4696 KB |
Output is correct |
26 |
Correct |
3 ms |
2904 KB |
Output is correct |
27 |
Correct |
3 ms |
4696 KB |
Output is correct |
28 |
Correct |
3 ms |
2904 KB |
Output is correct |
29 |
Correct |
42 ms |
12672 KB |
Output is correct |
30 |
Correct |
42 ms |
12796 KB |
Output is correct |
31 |
Correct |
3 ms |
4692 KB |
Output is correct |
32 |
Correct |
2 ms |
4696 KB |
Output is correct |
33 |
Correct |
2 ms |
4696 KB |
Output is correct |
34 |
Correct |
2 ms |
4696 KB |
Output is correct |
35 |
Correct |
11 ms |
5152 KB |
Output is correct |
36 |
Correct |
3 ms |
4696 KB |
Output is correct |
37 |
Correct |
50 ms |
12732 KB |
Output is correct |
38 |
Correct |
54 ms |
10848 KB |
Output is correct |
39 |
Correct |
2 ms |
4696 KB |
Output is correct |
40 |
Correct |
3 ms |
2648 KB |
Output is correct |
41 |
Correct |
2 ms |
2648 KB |
Output is correct |
42 |
Correct |
4 ms |
4696 KB |
Output is correct |
43 |
Execution timed out |
3043 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 |
2648 KB |
Output is correct |
3 |
Correct |
39 ms |
10440 KB |
Output is correct |
4 |
Correct |
34 ms |
12644 KB |
Output is correct |
5 |
Correct |
38 ms |
12676 KB |
Output is correct |
6 |
Correct |
41 ms |
12584 KB |
Output is correct |
7 |
Correct |
35 ms |
12632 KB |
Output is correct |
8 |
Correct |
47 ms |
12672 KB |
Output is correct |
9 |
Correct |
1 ms |
4696 KB |
Output is correct |
10 |
Correct |
1 ms |
4696 KB |
Output is correct |
11 |
Correct |
1 ms |
4696 KB |
Output is correct |
12 |
Correct |
2 ms |
4696 KB |
Output is correct |
13 |
Correct |
2 ms |
4696 KB |
Output is correct |
14 |
Correct |
1 ms |
4696 KB |
Output is correct |
15 |
Correct |
2 ms |
4696 KB |
Output is correct |
16 |
Correct |
3 ms |
4696 KB |
Output is correct |
17 |
Correct |
2 ms |
4696 KB |
Output is correct |
18 |
Correct |
2 ms |
4696 KB |
Output is correct |
19 |
Correct |
2 ms |
4696 KB |
Output is correct |
20 |
Correct |
1 ms |
4696 KB |
Output is correct |
21 |
Correct |
4 ms |
4696 KB |
Output is correct |
22 |
Correct |
3 ms |
4708 KB |
Output is correct |
23 |
Correct |
2 ms |
4696 KB |
Output is correct |
24 |
Correct |
2 ms |
4948 KB |
Output is correct |
25 |
Correct |
3 ms |
4696 KB |
Output is correct |
26 |
Correct |
3 ms |
2904 KB |
Output is correct |
27 |
Correct |
3 ms |
4696 KB |
Output is correct |
28 |
Correct |
3 ms |
2904 KB |
Output is correct |
29 |
Correct |
42 ms |
12672 KB |
Output is correct |
30 |
Correct |
42 ms |
12796 KB |
Output is correct |
31 |
Correct |
3 ms |
4692 KB |
Output is correct |
32 |
Correct |
2 ms |
4696 KB |
Output is correct |
33 |
Correct |
2 ms |
4696 KB |
Output is correct |
34 |
Correct |
2 ms |
4696 KB |
Output is correct |
35 |
Correct |
11 ms |
5152 KB |
Output is correct |
36 |
Correct |
3 ms |
4696 KB |
Output is correct |
37 |
Correct |
50 ms |
12732 KB |
Output is correct |
38 |
Correct |
54 ms |
10848 KB |
Output is correct |
39 |
Correct |
2 ms |
4696 KB |
Output is correct |
40 |
Correct |
3 ms |
2648 KB |
Output is correct |
41 |
Correct |
2 ms |
2648 KB |
Output is correct |
42 |
Correct |
4 ms |
4696 KB |
Output is correct |
43 |
Correct |
749 ms |
7000 KB |
Output is correct |
44 |
Runtime error |
47 ms |
18708 KB |
Execution killed with signal 11 |
45 |
Halted |
0 ms |
0 KB |
- |