#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
using ll = long long;
const int MOD = (int)1e9 + 2022;
int N, M, coeff[100005];
vector<int> A, adj[200005];
struct node {
node *left, *right;
int S, E, val;
node(int _s, int _e) : S(_s), E(_e) {
if (S == E) {
val = adj[S].size();
return;
}
int M = (S + E) / 2;
left = new node(S, M);
right = new node(M + 1, E);
val = (ll)left->val * right->val % MOD;
}
void upd(int p, int v) {
if (S == E) {
val = v;
return;
}
int M = (S + E) / 2;
if (p <= M) {
left->upd(p, v);
} else {
right->upd(p, v);
}
val = (ll)left->val * right->val % MOD;
}
} *root;
struct node2 {
node2 *left, *right;
int S, E, val[2];
bool ip;
node2(int _s, int _e) : S(_s), E(_e), ip(0) {
if (S == E) {
val[A[S]] = coeff[S];
val[!A[S]] = 0;
return;
}
int M = (S + E) / 2;
left = new node2(S, M);
right = new node2(M + 1, E);
val[0] = (left->val[0] + right->val[0]) % MOD;
val[1] = (left->val[1] + right->val[1]) % MOD;
}
void prop() {
if (S == E || !ip) {
return;
}
swap(left->val[0], left->val[1]);
swap(right->val[0], right->val[1]);
left->ip ^= 1;
right->ip ^= 1;
ip = 0;
}
void upd(int l, int r) {
if (l > E || r < S) {
return;
}
if (l <= S && E <= r) {
swap(val[0], val[1]);
ip ^= 1;
return;
}
prop();
left->upd(l, r);
right->upd(l, r);
val[0] = (left->val[0] + right->val[0]) % MOD;
val[1] = (left->val[1] + right->val[1]) % MOD;
}
} *root2;
void dfs(int u) {
if (u < N) {
root->upd(u, 1);
} else {
coeff[u - N] = root->val;
}
for (auto v : adj[u]) {
dfs(v);
}
if (u < N) {
root->upd(u, adj[u].size());
}
}
void init(int N, int M, vector<int> P, vector<int> A) {
::N = N;
::M = M;
::A = A;
for (int i = 0; i < N + M; i++) {
adj[P[i]].pb(i);
}
root = new node(0, N - 1);
dfs(0);
root2 = new node2(0, M - 1);
}
int count_ways(int L, int R) {
root2->upd(L - N, R - N);
return root2->val[1];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4952 KB |
Output is correct |
3 |
Correct |
2 ms |
5208 KB |
Output is correct |
4 |
Correct |
1 ms |
5368 KB |
Output is correct |
5 |
Correct |
1 ms |
5208 KB |
Output is correct |
6 |
Correct |
2 ms |
5208 KB |
Output is correct |
7 |
Correct |
3 ms |
5208 KB |
Output is correct |
8 |
Correct |
2 ms |
5208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
1 ms |
4952 KB |
Output is correct |
3 |
Correct |
2 ms |
5212 KB |
Output is correct |
4 |
Correct |
2 ms |
5208 KB |
Output is correct |
5 |
Correct |
1 ms |
5208 KB |
Output is correct |
6 |
Correct |
2 ms |
5208 KB |
Output is correct |
7 |
Correct |
3 ms |
5208 KB |
Output is correct |
8 |
Correct |
3 ms |
5208 KB |
Output is correct |
9 |
Correct |
3 ms |
5208 KB |
Output is correct |
10 |
Correct |
2 ms |
5208 KB |
Output is correct |
11 |
Correct |
2 ms |
5208 KB |
Output is correct |
12 |
Correct |
3 ms |
5208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4952 KB |
Output is correct |
3 |
Correct |
2 ms |
5208 KB |
Output is correct |
4 |
Correct |
1 ms |
5368 KB |
Output is correct |
5 |
Correct |
1 ms |
5208 KB |
Output is correct |
6 |
Correct |
2 ms |
5208 KB |
Output is correct |
7 |
Correct |
3 ms |
5208 KB |
Output is correct |
8 |
Correct |
2 ms |
5208 KB |
Output is correct |
9 |
Correct |
2 ms |
4952 KB |
Output is correct |
10 |
Correct |
1 ms |
4952 KB |
Output is correct |
11 |
Correct |
2 ms |
5212 KB |
Output is correct |
12 |
Correct |
2 ms |
5208 KB |
Output is correct |
13 |
Correct |
1 ms |
5208 KB |
Output is correct |
14 |
Correct |
2 ms |
5208 KB |
Output is correct |
15 |
Correct |
3 ms |
5208 KB |
Output is correct |
16 |
Correct |
3 ms |
5208 KB |
Output is correct |
17 |
Correct |
3 ms |
5208 KB |
Output is correct |
18 |
Correct |
2 ms |
5208 KB |
Output is correct |
19 |
Correct |
2 ms |
5208 KB |
Output is correct |
20 |
Correct |
3 ms |
5208 KB |
Output is correct |
21 |
Correct |
2 ms |
5208 KB |
Output is correct |
22 |
Correct |
2 ms |
5208 KB |
Output is correct |
23 |
Correct |
2 ms |
5208 KB |
Output is correct |
24 |
Correct |
2 ms |
5208 KB |
Output is correct |
25 |
Correct |
2 ms |
5208 KB |
Output is correct |
26 |
Correct |
2 ms |
5208 KB |
Output is correct |
27 |
Correct |
3 ms |
5208 KB |
Output is correct |
28 |
Correct |
2 ms |
5208 KB |
Output is correct |
29 |
Correct |
1 ms |
5208 KB |
Output is correct |
30 |
Correct |
2 ms |
5208 KB |
Output is correct |
31 |
Correct |
1 ms |
5208 KB |
Output is correct |
32 |
Correct |
2 ms |
5240 KB |
Output is correct |
33 |
Correct |
2 ms |
5208 KB |
Output is correct |
34 |
Correct |
1 ms |
5208 KB |
Output is correct |
35 |
Correct |
2 ms |
5208 KB |
Output is correct |
36 |
Correct |
2 ms |
5464 KB |
Output is correct |
37 |
Correct |
3 ms |
5464 KB |
Output is correct |
38 |
Correct |
2 ms |
5464 KB |
Output is correct |
39 |
Correct |
1 ms |
5208 KB |
Output is correct |
40 |
Correct |
2 ms |
5208 KB |
Output is correct |
41 |
Correct |
2 ms |
5208 KB |
Output is correct |
42 |
Correct |
2 ms |
5212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
496 ms |
13364 KB |
Output is correct |
2 |
Correct |
735 ms |
21336 KB |
Output is correct |
3 |
Correct |
754 ms |
21328 KB |
Output is correct |
4 |
Correct |
724 ms |
21328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
496 ms |
13364 KB |
Output is correct |
2 |
Correct |
735 ms |
21336 KB |
Output is correct |
3 |
Correct |
754 ms |
21328 KB |
Output is correct |
4 |
Correct |
724 ms |
21328 KB |
Output is correct |
5 |
Correct |
597 ms |
13136 KB |
Output is correct |
6 |
Correct |
749 ms |
21328 KB |
Output is correct |
7 |
Correct |
786 ms |
21324 KB |
Output is correct |
8 |
Correct |
719 ms |
21432 KB |
Output is correct |
9 |
Correct |
319 ms |
5464 KB |
Output is correct |
10 |
Correct |
668 ms |
5976 KB |
Output is correct |
11 |
Correct |
638 ms |
5976 KB |
Output is correct |
12 |
Correct |
651 ms |
5976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
1 ms |
4952 KB |
Output is correct |
3 |
Correct |
2 ms |
5212 KB |
Output is correct |
4 |
Correct |
2 ms |
5208 KB |
Output is correct |
5 |
Correct |
1 ms |
5208 KB |
Output is correct |
6 |
Correct |
2 ms |
5208 KB |
Output is correct |
7 |
Correct |
3 ms |
5208 KB |
Output is correct |
8 |
Correct |
3 ms |
5208 KB |
Output is correct |
9 |
Correct |
3 ms |
5208 KB |
Output is correct |
10 |
Correct |
2 ms |
5208 KB |
Output is correct |
11 |
Correct |
2 ms |
5208 KB |
Output is correct |
12 |
Correct |
3 ms |
5208 KB |
Output is correct |
13 |
Correct |
496 ms |
13364 KB |
Output is correct |
14 |
Correct |
735 ms |
21336 KB |
Output is correct |
15 |
Correct |
754 ms |
21328 KB |
Output is correct |
16 |
Correct |
724 ms |
21328 KB |
Output is correct |
17 |
Correct |
597 ms |
13136 KB |
Output is correct |
18 |
Correct |
749 ms |
21328 KB |
Output is correct |
19 |
Correct |
786 ms |
21324 KB |
Output is correct |
20 |
Correct |
719 ms |
21432 KB |
Output is correct |
21 |
Correct |
319 ms |
5464 KB |
Output is correct |
22 |
Correct |
668 ms |
5976 KB |
Output is correct |
23 |
Correct |
638 ms |
5976 KB |
Output is correct |
24 |
Correct |
651 ms |
5976 KB |
Output is correct |
25 |
Correct |
820 ms |
29524 KB |
Output is correct |
26 |
Correct |
830 ms |
30032 KB |
Output is correct |
27 |
Correct |
817 ms |
30024 KB |
Output is correct |
28 |
Correct |
639 ms |
29996 KB |
Output is correct |
29 |
Correct |
811 ms |
37960 KB |
Output is correct |
30 |
Correct |
687 ms |
37968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4952 KB |
Output is correct |
3 |
Correct |
2 ms |
5208 KB |
Output is correct |
4 |
Correct |
1 ms |
5368 KB |
Output is correct |
5 |
Correct |
1 ms |
5208 KB |
Output is correct |
6 |
Correct |
2 ms |
5208 KB |
Output is correct |
7 |
Correct |
3 ms |
5208 KB |
Output is correct |
8 |
Correct |
2 ms |
5208 KB |
Output is correct |
9 |
Correct |
2 ms |
4952 KB |
Output is correct |
10 |
Correct |
1 ms |
4952 KB |
Output is correct |
11 |
Correct |
2 ms |
5212 KB |
Output is correct |
12 |
Correct |
2 ms |
5208 KB |
Output is correct |
13 |
Correct |
1 ms |
5208 KB |
Output is correct |
14 |
Correct |
2 ms |
5208 KB |
Output is correct |
15 |
Correct |
3 ms |
5208 KB |
Output is correct |
16 |
Correct |
3 ms |
5208 KB |
Output is correct |
17 |
Correct |
3 ms |
5208 KB |
Output is correct |
18 |
Correct |
2 ms |
5208 KB |
Output is correct |
19 |
Correct |
2 ms |
5208 KB |
Output is correct |
20 |
Correct |
3 ms |
5208 KB |
Output is correct |
21 |
Correct |
2 ms |
5208 KB |
Output is correct |
22 |
Correct |
2 ms |
5208 KB |
Output is correct |
23 |
Correct |
2 ms |
5208 KB |
Output is correct |
24 |
Correct |
2 ms |
5208 KB |
Output is correct |
25 |
Correct |
2 ms |
5208 KB |
Output is correct |
26 |
Correct |
2 ms |
5208 KB |
Output is correct |
27 |
Correct |
3 ms |
5208 KB |
Output is correct |
28 |
Correct |
2 ms |
5208 KB |
Output is correct |
29 |
Correct |
1 ms |
5208 KB |
Output is correct |
30 |
Correct |
2 ms |
5208 KB |
Output is correct |
31 |
Correct |
1 ms |
5208 KB |
Output is correct |
32 |
Correct |
2 ms |
5240 KB |
Output is correct |
33 |
Correct |
2 ms |
5208 KB |
Output is correct |
34 |
Correct |
1 ms |
5208 KB |
Output is correct |
35 |
Correct |
2 ms |
5208 KB |
Output is correct |
36 |
Correct |
2 ms |
5464 KB |
Output is correct |
37 |
Correct |
3 ms |
5464 KB |
Output is correct |
38 |
Correct |
2 ms |
5464 KB |
Output is correct |
39 |
Correct |
1 ms |
5208 KB |
Output is correct |
40 |
Correct |
2 ms |
5208 KB |
Output is correct |
41 |
Correct |
2 ms |
5208 KB |
Output is correct |
42 |
Correct |
2 ms |
5212 KB |
Output is correct |
43 |
Correct |
494 ms |
5972 KB |
Output is correct |
44 |
Correct |
702 ms |
5972 KB |
Output is correct |
45 |
Correct |
648 ms |
5720 KB |
Output is correct |
46 |
Correct |
646 ms |
6232 KB |
Output is correct |
47 |
Correct |
638 ms |
6232 KB |
Output is correct |
48 |
Correct |
641 ms |
6232 KB |
Output is correct |
49 |
Correct |
722 ms |
6232 KB |
Output is correct |
50 |
Correct |
611 ms |
6232 KB |
Output is correct |
51 |
Correct |
626 ms |
5720 KB |
Output is correct |
52 |
Correct |
600 ms |
5720 KB |
Output is correct |
53 |
Correct |
613 ms |
5976 KB |
Output is correct |
54 |
Correct |
628 ms |
6232 KB |
Output is correct |
55 |
Correct |
654 ms |
5976 KB |
Output is correct |
56 |
Correct |
655 ms |
5720 KB |
Output is correct |
57 |
Correct |
680 ms |
5720 KB |
Output is correct |
58 |
Correct |
631 ms |
6744 KB |
Output is correct |
59 |
Correct |
658 ms |
6744 KB |
Output is correct |
60 |
Correct |
547 ms |
6744 KB |
Output is correct |
61 |
Correct |
606 ms |
5976 KB |
Output is correct |
62 |
Correct |
652 ms |
5720 KB |
Output is correct |
63 |
Correct |
672 ms |
5720 KB |
Output is correct |
64 |
Correct |
619 ms |
5720 KB |
Output is correct |
65 |
Correct |
275 ms |
5464 KB |
Output is correct |
66 |
Correct |
709 ms |
5976 KB |
Output is correct |
67 |
Correct |
661 ms |
5976 KB |
Output is correct |
68 |
Correct |
633 ms |
5976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4952 KB |
Output is correct |
3 |
Correct |
2 ms |
5208 KB |
Output is correct |
4 |
Correct |
1 ms |
5368 KB |
Output is correct |
5 |
Correct |
1 ms |
5208 KB |
Output is correct |
6 |
Correct |
2 ms |
5208 KB |
Output is correct |
7 |
Correct |
3 ms |
5208 KB |
Output is correct |
8 |
Correct |
2 ms |
5208 KB |
Output is correct |
9 |
Correct |
2 ms |
4952 KB |
Output is correct |
10 |
Correct |
1 ms |
4952 KB |
Output is correct |
11 |
Correct |
2 ms |
5212 KB |
Output is correct |
12 |
Correct |
2 ms |
5208 KB |
Output is correct |
13 |
Correct |
1 ms |
5208 KB |
Output is correct |
14 |
Correct |
2 ms |
5208 KB |
Output is correct |
15 |
Correct |
3 ms |
5208 KB |
Output is correct |
16 |
Correct |
3 ms |
5208 KB |
Output is correct |
17 |
Correct |
3 ms |
5208 KB |
Output is correct |
18 |
Correct |
2 ms |
5208 KB |
Output is correct |
19 |
Correct |
2 ms |
5208 KB |
Output is correct |
20 |
Correct |
3 ms |
5208 KB |
Output is correct |
21 |
Correct |
2 ms |
5208 KB |
Output is correct |
22 |
Correct |
2 ms |
5208 KB |
Output is correct |
23 |
Correct |
2 ms |
5208 KB |
Output is correct |
24 |
Correct |
2 ms |
5208 KB |
Output is correct |
25 |
Correct |
2 ms |
5208 KB |
Output is correct |
26 |
Correct |
2 ms |
5208 KB |
Output is correct |
27 |
Correct |
3 ms |
5208 KB |
Output is correct |
28 |
Correct |
2 ms |
5208 KB |
Output is correct |
29 |
Correct |
1 ms |
5208 KB |
Output is correct |
30 |
Correct |
2 ms |
5208 KB |
Output is correct |
31 |
Correct |
1 ms |
5208 KB |
Output is correct |
32 |
Correct |
2 ms |
5240 KB |
Output is correct |
33 |
Correct |
2 ms |
5208 KB |
Output is correct |
34 |
Correct |
1 ms |
5208 KB |
Output is correct |
35 |
Correct |
2 ms |
5208 KB |
Output is correct |
36 |
Correct |
2 ms |
5464 KB |
Output is correct |
37 |
Correct |
3 ms |
5464 KB |
Output is correct |
38 |
Correct |
2 ms |
5464 KB |
Output is correct |
39 |
Correct |
1 ms |
5208 KB |
Output is correct |
40 |
Correct |
2 ms |
5208 KB |
Output is correct |
41 |
Correct |
2 ms |
5208 KB |
Output is correct |
42 |
Correct |
2 ms |
5212 KB |
Output is correct |
43 |
Correct |
496 ms |
13364 KB |
Output is correct |
44 |
Correct |
735 ms |
21336 KB |
Output is correct |
45 |
Correct |
754 ms |
21328 KB |
Output is correct |
46 |
Correct |
724 ms |
21328 KB |
Output is correct |
47 |
Correct |
597 ms |
13136 KB |
Output is correct |
48 |
Correct |
749 ms |
21328 KB |
Output is correct |
49 |
Correct |
786 ms |
21324 KB |
Output is correct |
50 |
Correct |
719 ms |
21432 KB |
Output is correct |
51 |
Correct |
319 ms |
5464 KB |
Output is correct |
52 |
Correct |
668 ms |
5976 KB |
Output is correct |
53 |
Correct |
638 ms |
5976 KB |
Output is correct |
54 |
Correct |
651 ms |
5976 KB |
Output is correct |
55 |
Correct |
820 ms |
29524 KB |
Output is correct |
56 |
Correct |
830 ms |
30032 KB |
Output is correct |
57 |
Correct |
817 ms |
30024 KB |
Output is correct |
58 |
Correct |
639 ms |
29996 KB |
Output is correct |
59 |
Correct |
811 ms |
37960 KB |
Output is correct |
60 |
Correct |
687 ms |
37968 KB |
Output is correct |
61 |
Correct |
494 ms |
5972 KB |
Output is correct |
62 |
Correct |
702 ms |
5972 KB |
Output is correct |
63 |
Correct |
648 ms |
5720 KB |
Output is correct |
64 |
Correct |
646 ms |
6232 KB |
Output is correct |
65 |
Correct |
638 ms |
6232 KB |
Output is correct |
66 |
Correct |
641 ms |
6232 KB |
Output is correct |
67 |
Correct |
722 ms |
6232 KB |
Output is correct |
68 |
Correct |
611 ms |
6232 KB |
Output is correct |
69 |
Correct |
626 ms |
5720 KB |
Output is correct |
70 |
Correct |
600 ms |
5720 KB |
Output is correct |
71 |
Correct |
613 ms |
5976 KB |
Output is correct |
72 |
Correct |
628 ms |
6232 KB |
Output is correct |
73 |
Correct |
654 ms |
5976 KB |
Output is correct |
74 |
Correct |
655 ms |
5720 KB |
Output is correct |
75 |
Correct |
680 ms |
5720 KB |
Output is correct |
76 |
Correct |
631 ms |
6744 KB |
Output is correct |
77 |
Correct |
658 ms |
6744 KB |
Output is correct |
78 |
Correct |
547 ms |
6744 KB |
Output is correct |
79 |
Correct |
606 ms |
5976 KB |
Output is correct |
80 |
Correct |
652 ms |
5720 KB |
Output is correct |
81 |
Correct |
672 ms |
5720 KB |
Output is correct |
82 |
Correct |
619 ms |
5720 KB |
Output is correct |
83 |
Correct |
275 ms |
5464 KB |
Output is correct |
84 |
Correct |
709 ms |
5976 KB |
Output is correct |
85 |
Correct |
661 ms |
5976 KB |
Output is correct |
86 |
Correct |
633 ms |
5976 KB |
Output is correct |
87 |
Correct |
2 ms |
4952 KB |
Output is correct |
88 |
Correct |
493 ms |
27128 KB |
Output is correct |
89 |
Correct |
746 ms |
21328 KB |
Output is correct |
90 |
Correct |
771 ms |
20816 KB |
Output is correct |
91 |
Correct |
733 ms |
30032 KB |
Output is correct |
92 |
Correct |
874 ms |
30044 KB |
Output is correct |
93 |
Correct |
894 ms |
30124 KB |
Output is correct |
94 |
Correct |
857 ms |
30032 KB |
Output is correct |
95 |
Correct |
805 ms |
30108 KB |
Output is correct |
96 |
Correct |
696 ms |
17096 KB |
Output is correct |
97 |
Correct |
753 ms |
17096 KB |
Output is correct |
98 |
Correct |
639 ms |
26200 KB |
Output is correct |
99 |
Correct |
797 ms |
30128 KB |
Output is correct |
100 |
Correct |
810 ms |
23376 KB |
Output is correct |
101 |
Correct |
703 ms |
20496 KB |
Output is correct |
102 |
Correct |
757 ms |
17240 KB |
Output is correct |
103 |
Correct |
773 ms |
37800 KB |
Output is correct |
104 |
Correct |
733 ms |
38360 KB |
Output is correct |
105 |
Correct |
734 ms |
38312 KB |
Output is correct |
106 |
Correct |
729 ms |
21840 KB |
Output is correct |
107 |
Correct |
751 ms |
18344 KB |
Output is correct |
108 |
Correct |
752 ms |
18256 KB |
Output is correct |
109 |
Correct |
784 ms |
17240 KB |
Output is correct |