#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000002022;
struct Vertex {
int s0, s1;
};
vector<int> c, now;
int dim, subtract;
vector<Vertex> tree;
vector<int> lazy;
void build(int v, int tl, int tr) {
lazy[v] = 0;
if (tl == tr) {
tree[v].s0 = now[tl] * c[tl];
tree[v].s1 = (1 - now[tl]) * c[tl];
} else {
int tm = (tl + tr) / 2;
build(2 * v, tl, tm);
build(2 * v + 1, tm + 1, tr);
tree[v].s0 = tree[2 * v].s0 + tree[2 * v + 1].s0;
tree[v].s1 = tree[2 * v].s1 + tree[2 * v + 1].s1;
if (tree[v].s0 >= MOD) tree[v].s0 -= MOD;
if (tree[v].s1 >= MOD) tree[v].s1 -= MOD;
}
}
void push(int v, int tl, int tr) {
if (lazy[v]) {
swap(tree[v].s0, tree[v].s1);
if (tl < tr) lazy[2 * v] ^= 1, lazy[2 * v + 1] ^= 1;
lazy[v] = 0;
}
}
void op(int v, int tl, int tr, int l, int r) {
push(v, tl, tr);
if (tr < l || r < tl) return;
if (l <= tl && tr <= r) {
lazy[v] ^= 1;
push(v, tl, tr);
return;
}
int tm = (tl + tr) / 2;
op(2 * v, tl, tm, l, r);
op(2 * v + 1, tm + 1, tr, l, r);
tree[v].s0 = tree[2 * v].s0 + tree[2 * v + 1].s0;
tree[v].s1 = tree[2 * v].s1 + tree[2 * v + 1].s1;
if (tree[v].s0 >= MOD) tree[v].s0 -= MOD;
if (tree[v].s1 >= MOD) tree[v].s1 -= MOD;
}
void init(int n, int m, std::vector<int> par, std::vector<int> init) {
dim = m;
tree.resize(4 * dim + 7);
lazy.resize(4 * dim + 7);
subtract = n;
c.resize(m, 0);
vector<vector<int>> g(n + m);
vector<int> prod(n + m, 1);
for (int i = 1; i < n + m; i++) {
g[par[i]].push_back(i);
}
function<void(int)> build1 = [&] (int a) {
if (g[a].empty()) return;
prod[a] = (int) g[a].size();
for (auto &b : g[a]) {
build1(b);
prod[a] = prod[a] * (ll) prod[b] % MOD;
}
};
now = init;
function<void(int, int)> dfs = [&] (int a, int coef) {
/// optimize this function
for (int i = 0; i < (int) g[a].size(); i++) {
int send = coef;
for (int j = 0; j < (int) g[a].size(); j++) {
if (i != j) {
send = send * (ll) prod[g[a][j]] % MOD;
}
}
dfs(g[a][i], send);
}
if (g[a].empty()) {
assert(n + 0 <= a && a < n + m);
c[a - n] = coef;
}
};
build1(0);
dfs(0, 1);
build(1, 0, dim - 1);
}
int count_ways(int l, int r) {
l -= subtract;
r -= subtract;
op(1, 0, dim - 1, l, r);
push(1, 0, dim - 1);
return tree[1].s0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
5 ms |
336 KB |
Output is correct |
4 |
Correct |
6 ms |
400 KB |
Output is correct |
5 |
Correct |
6 ms |
336 KB |
Output is correct |
6 |
Correct |
6 ms |
396 KB |
Output is correct |
7 |
Correct |
6 ms |
400 KB |
Output is correct |
8 |
Correct |
6 ms |
396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
2 ms |
484 KB |
Output is correct |
9 |
Correct |
2 ms |
336 KB |
Output is correct |
10 |
Correct |
2 ms |
492 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
2 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
5 ms |
336 KB |
Output is correct |
4 |
Correct |
6 ms |
400 KB |
Output is correct |
5 |
Correct |
6 ms |
336 KB |
Output is correct |
6 |
Correct |
6 ms |
396 KB |
Output is correct |
7 |
Correct |
6 ms |
400 KB |
Output is correct |
8 |
Correct |
6 ms |
396 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
300 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
2 ms |
484 KB |
Output is correct |
17 |
Correct |
2 ms |
336 KB |
Output is correct |
18 |
Correct |
2 ms |
492 KB |
Output is correct |
19 |
Correct |
1 ms |
464 KB |
Output is correct |
20 |
Correct |
2 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
464 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
6 ms |
396 KB |
Output is correct |
30 |
Correct |
7 ms |
400 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
2 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
464 KB |
Output is correct |
37 |
Correct |
6 ms |
532 KB |
Output is correct |
38 |
Correct |
6 ms |
464 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
2 ms |
336 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
808 ms |
5668 KB |
Output is correct |
2 |
Correct |
962 ms |
11056 KB |
Output is correct |
3 |
Correct |
774 ms |
11040 KB |
Output is correct |
4 |
Correct |
816 ms |
11032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
808 ms |
5668 KB |
Output is correct |
2 |
Correct |
962 ms |
11056 KB |
Output is correct |
3 |
Correct |
774 ms |
11040 KB |
Output is correct |
4 |
Correct |
816 ms |
11032 KB |
Output is correct |
5 |
Correct |
746 ms |
5600 KB |
Output is correct |
6 |
Correct |
877 ms |
11056 KB |
Output is correct |
7 |
Correct |
794 ms |
11048 KB |
Output is correct |
8 |
Correct |
953 ms |
11080 KB |
Output is correct |
9 |
Correct |
432 ms |
592 KB |
Output is correct |
10 |
Correct |
492 ms |
980 KB |
Output is correct |
11 |
Correct |
896 ms |
848 KB |
Output is correct |
12 |
Correct |
781 ms |
976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
2 ms |
484 KB |
Output is correct |
9 |
Correct |
2 ms |
336 KB |
Output is correct |
10 |
Correct |
2 ms |
492 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
2 ms |
336 KB |
Output is correct |
13 |
Correct |
808 ms |
5668 KB |
Output is correct |
14 |
Correct |
962 ms |
11056 KB |
Output is correct |
15 |
Correct |
774 ms |
11040 KB |
Output is correct |
16 |
Correct |
816 ms |
11032 KB |
Output is correct |
17 |
Correct |
746 ms |
5600 KB |
Output is correct |
18 |
Correct |
877 ms |
11056 KB |
Output is correct |
19 |
Correct |
794 ms |
11048 KB |
Output is correct |
20 |
Correct |
953 ms |
11080 KB |
Output is correct |
21 |
Correct |
432 ms |
592 KB |
Output is correct |
22 |
Correct |
492 ms |
980 KB |
Output is correct |
23 |
Correct |
896 ms |
848 KB |
Output is correct |
24 |
Correct |
781 ms |
976 KB |
Output is correct |
25 |
Correct |
933 ms |
16444 KB |
Output is correct |
26 |
Correct |
900 ms |
16668 KB |
Output is correct |
27 |
Correct |
1099 ms |
16748 KB |
Output is correct |
28 |
Correct |
754 ms |
16676 KB |
Output is correct |
29 |
Correct |
1064 ms |
24476 KB |
Output is correct |
30 |
Correct |
938 ms |
24476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
5 ms |
336 KB |
Output is correct |
4 |
Correct |
6 ms |
400 KB |
Output is correct |
5 |
Correct |
6 ms |
336 KB |
Output is correct |
6 |
Correct |
6 ms |
396 KB |
Output is correct |
7 |
Correct |
6 ms |
400 KB |
Output is correct |
8 |
Correct |
6 ms |
396 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
300 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
2 ms |
484 KB |
Output is correct |
17 |
Correct |
2 ms |
336 KB |
Output is correct |
18 |
Correct |
2 ms |
492 KB |
Output is correct |
19 |
Correct |
1 ms |
464 KB |
Output is correct |
20 |
Correct |
2 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
464 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
6 ms |
396 KB |
Output is correct |
30 |
Correct |
7 ms |
400 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
2 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
464 KB |
Output is correct |
37 |
Correct |
6 ms |
532 KB |
Output is correct |
38 |
Correct |
6 ms |
464 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
2 ms |
336 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
43 |
Correct |
672 ms |
720 KB |
Output is correct |
44 |
Correct |
921 ms |
720 KB |
Output is correct |
45 |
Correct |
894 ms |
720 KB |
Output is correct |
46 |
Correct |
880 ms |
1104 KB |
Output is correct |
47 |
Correct |
821 ms |
1104 KB |
Output is correct |
48 |
Correct |
969 ms |
1104 KB |
Output is correct |
49 |
Correct |
914 ms |
1104 KB |
Output is correct |
50 |
Correct |
724 ms |
1104 KB |
Output is correct |
51 |
Correct |
706 ms |
812 KB |
Output is correct |
52 |
Correct |
1012 ms |
720 KB |
Output is correct |
53 |
Correct |
996 ms |
924 KB |
Output is correct |
54 |
Correct |
897 ms |
1104 KB |
Output is correct |
55 |
Correct |
1043 ms |
848 KB |
Output is correct |
56 |
Correct |
878 ms |
848 KB |
Output is correct |
57 |
Correct |
616 ms |
720 KB |
Output is correct |
58 |
Correct |
953 ms |
1536 KB |
Output is correct |
59 |
Correct |
959 ms |
1532 KB |
Output is correct |
60 |
Correct |
1108 ms |
1488 KB |
Output is correct |
61 |
Correct |
1075 ms |
880 KB |
Output is correct |
62 |
Correct |
826 ms |
768 KB |
Output is correct |
63 |
Correct |
858 ms |
768 KB |
Output is correct |
64 |
Correct |
931 ms |
720 KB |
Output is correct |
65 |
Correct |
449 ms |
592 KB |
Output is correct |
66 |
Correct |
814 ms |
996 KB |
Output is correct |
67 |
Correct |
919 ms |
976 KB |
Output is correct |
68 |
Correct |
814 ms |
976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
5 ms |
336 KB |
Output is correct |
4 |
Correct |
6 ms |
400 KB |
Output is correct |
5 |
Correct |
6 ms |
336 KB |
Output is correct |
6 |
Correct |
6 ms |
396 KB |
Output is correct |
7 |
Correct |
6 ms |
400 KB |
Output is correct |
8 |
Correct |
6 ms |
396 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
300 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
2 ms |
484 KB |
Output is correct |
17 |
Correct |
2 ms |
336 KB |
Output is correct |
18 |
Correct |
2 ms |
492 KB |
Output is correct |
19 |
Correct |
1 ms |
464 KB |
Output is correct |
20 |
Correct |
2 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
464 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
6 ms |
396 KB |
Output is correct |
30 |
Correct |
7 ms |
400 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
2 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
464 KB |
Output is correct |
37 |
Correct |
6 ms |
532 KB |
Output is correct |
38 |
Correct |
6 ms |
464 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
2 ms |
336 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
43 |
Correct |
808 ms |
5668 KB |
Output is correct |
44 |
Correct |
962 ms |
11056 KB |
Output is correct |
45 |
Correct |
774 ms |
11040 KB |
Output is correct |
46 |
Correct |
816 ms |
11032 KB |
Output is correct |
47 |
Correct |
746 ms |
5600 KB |
Output is correct |
48 |
Correct |
877 ms |
11056 KB |
Output is correct |
49 |
Correct |
794 ms |
11048 KB |
Output is correct |
50 |
Correct |
953 ms |
11080 KB |
Output is correct |
51 |
Correct |
432 ms |
592 KB |
Output is correct |
52 |
Correct |
492 ms |
980 KB |
Output is correct |
53 |
Correct |
896 ms |
848 KB |
Output is correct |
54 |
Correct |
781 ms |
976 KB |
Output is correct |
55 |
Correct |
933 ms |
16444 KB |
Output is correct |
56 |
Correct |
900 ms |
16668 KB |
Output is correct |
57 |
Correct |
1099 ms |
16748 KB |
Output is correct |
58 |
Correct |
754 ms |
16676 KB |
Output is correct |
59 |
Correct |
1064 ms |
24476 KB |
Output is correct |
60 |
Correct |
938 ms |
24476 KB |
Output is correct |
61 |
Correct |
672 ms |
720 KB |
Output is correct |
62 |
Correct |
921 ms |
720 KB |
Output is correct |
63 |
Correct |
894 ms |
720 KB |
Output is correct |
64 |
Correct |
880 ms |
1104 KB |
Output is correct |
65 |
Correct |
821 ms |
1104 KB |
Output is correct |
66 |
Correct |
969 ms |
1104 KB |
Output is correct |
67 |
Correct |
914 ms |
1104 KB |
Output is correct |
68 |
Correct |
724 ms |
1104 KB |
Output is correct |
69 |
Correct |
706 ms |
812 KB |
Output is correct |
70 |
Correct |
1012 ms |
720 KB |
Output is correct |
71 |
Correct |
996 ms |
924 KB |
Output is correct |
72 |
Correct |
897 ms |
1104 KB |
Output is correct |
73 |
Correct |
1043 ms |
848 KB |
Output is correct |
74 |
Correct |
878 ms |
848 KB |
Output is correct |
75 |
Correct |
616 ms |
720 KB |
Output is correct |
76 |
Correct |
953 ms |
1536 KB |
Output is correct |
77 |
Correct |
959 ms |
1532 KB |
Output is correct |
78 |
Correct |
1108 ms |
1488 KB |
Output is correct |
79 |
Correct |
1075 ms |
880 KB |
Output is correct |
80 |
Correct |
826 ms |
768 KB |
Output is correct |
81 |
Correct |
858 ms |
768 KB |
Output is correct |
82 |
Correct |
931 ms |
720 KB |
Output is correct |
83 |
Correct |
449 ms |
592 KB |
Output is correct |
84 |
Correct |
814 ms |
996 KB |
Output is correct |
85 |
Correct |
919 ms |
976 KB |
Output is correct |
86 |
Correct |
814 ms |
976 KB |
Output is correct |
87 |
Correct |
0 ms |
208 KB |
Output is correct |
88 |
Correct |
474 ms |
14604 KB |
Output is correct |
89 |
Correct |
1002 ms |
10336 KB |
Output is correct |
90 |
Correct |
1016 ms |
10312 KB |
Output is correct |
91 |
Correct |
901 ms |
16800 KB |
Output is correct |
92 |
Correct |
1108 ms |
16852 KB |
Output is correct |
93 |
Correct |
1155 ms |
16820 KB |
Output is correct |
94 |
Correct |
1052 ms |
16852 KB |
Output is correct |
95 |
Correct |
877 ms |
16748 KB |
Output is correct |
96 |
Execution timed out |
3040 ms |
10548 KB |
Time limit exceeded |
97 |
Halted |
0 ms |
0 KB |
- |