#include "circuit.h"
#include<bits/stdc++.h>
using namespace std;
#define int long long int
vector<int> adj[200005];
int v[200005], a[200005], arr[200005], brr[200005], seg1[4*200005], seg0[4*200005], s[4*200005], dep[200005], mod = 1000002022;
void lazypropagate(int n, int l, int r) {
if (s[n]) {
swap(seg1[n], seg0[n]);
if (l != r) {
s[2*n] ^= 1;
s[2*n+1] ^= 1;
}
s[n] = 0;
}
}
void build(int n, int l, int r) {
if (l == r) {
seg1[n] = arr[l];
seg0[n] = brr[l];
} else {
int m = (l+r)/2;
build(2*n, l, m);
build(2*n+1, m+1, r);
seg1[n] = seg1[2*n] + seg1[2*n+1];
seg1[n] %= mod;
seg0[n] = seg0[2*n] + seg0[2*n+1];
seg0[n] %= mod;
}
}
void update(int n, int l, int r, int a, int b) {
lazypropagate(n, l, r);
if (b < l || r < a) {
return;
} else if (a <= l && r <= b) {
s[n] = 1;
lazypropagate(n, l, r);
} else {
int m = (l+r)/2;
update(2*n, l, m, a, b);
update(2*n+1, m+1, r, a, b);
seg1[n] = seg1[2*n] + seg1[2*n+1];
seg1[n] %= mod;
seg0[n] = seg0[2*n] + seg0[2*n+1];
seg0[n] %= mod;
}
}
int n, m;
void dfs1(int i) {
if (adj[i].size() == 0) {
v[i] = 1;
} else {
v[i] = adj[i].size();
}
for (int j : adj[i]) {
dfs1(j);
}
for (int j : adj[i]) {
v[i] *= v[j];
v[i] %= mod;
}
}
void dfs2(int i, int va) {
if (adj[i].size() == 0) {
a[i] = va;
return;
}
int l = adj[i].size();
vector<int> pref(l+2, 1), suff(l+2, 1);
for (int j = 1; j <= l; j++) {
pref[j] = v[adj[i][j-1]];
suff[j] = v[adj[i][j-1]];
}
for (int j = 1; j <= l+1; j++) {
pref[j] *= pref[j-1];
pref[j] %= mod;
}
for (int j = l; j >= 0; j--) {
suff[j] *= suff[j+1];
suff[j] %= mod;
}
for (int j = 1; j <= l; j++) {
int b = pref[j-1]*suff[j+1];
b %= mod;
b *= va;
b %= mod;
dfs2(adj[i][j-1], b);
}
}
void init(int32_t N, int32_t M, vector<int32_t> P, vector<int32_t> A) {
n = N, m = M;
for (int i = 1; i <= n+m-1; i++) {
adj[P[i]].push_back(i);
}
vector<int> b(n+1, 1);
for (int i = 1; i <= n; i++) {
b[i] = b[i-1]*2;
b[i] %= mod;
}
dfs1(0);
dfs2(0, 1);
for (int i = 0; i < m; i++) {
if (A[i]) {
arr[i] = a[i+n];
} else {
brr[i] = a[i+n];
}
}
build(1, 0, m-1);
}
int32_t count_ways(int32_t L, int32_t R) {
update(1, 0, m-1, L-n, R-n);
return seg1[1];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4952 KB |
Output is correct |
2 |
Correct |
3 ms |
4952 KB |
Output is correct |
3 |
Correct |
3 ms |
5312 KB |
Output is correct |
4 |
Correct |
2 ms |
5208 KB |
Output is correct |
5 |
Correct |
2 ms |
5208 KB |
Output is correct |
6 |
Correct |
2 ms |
5208 KB |
Output is correct |
7 |
Correct |
2 ms |
5208 KB |
Output is correct |
8 |
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 |
3 ms |
5208 KB |
Output is correct |
3 |
Correct |
3 ms |
5208 KB |
Output is correct |
4 |
Correct |
2 ms |
5208 KB |
Output is correct |
5 |
Correct |
4 ms |
5212 KB |
Output is correct |
6 |
Correct |
2 ms |
5208 KB |
Output is correct |
7 |
Correct |
2 ms |
5208 KB |
Output is correct |
8 |
Correct |
3 ms |
5208 KB |
Output is correct |
9 |
Correct |
2 ms |
5208 KB |
Output is correct |
10 |
Correct |
4 ms |
5464 KB |
Output is correct |
11 |
Correct |
3 ms |
5404 KB |
Output is correct |
12 |
Correct |
3 ms |
5208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4952 KB |
Output is correct |
2 |
Correct |
3 ms |
4952 KB |
Output is correct |
3 |
Correct |
3 ms |
5312 KB |
Output is correct |
4 |
Correct |
2 ms |
5208 KB |
Output is correct |
5 |
Correct |
2 ms |
5208 KB |
Output is correct |
6 |
Correct |
2 ms |
5208 KB |
Output is correct |
7 |
Correct |
2 ms |
5208 KB |
Output is correct |
8 |
Correct |
3 ms |
5208 KB |
Output is correct |
9 |
Correct |
2 ms |
4952 KB |
Output is correct |
10 |
Correct |
3 ms |
5208 KB |
Output is correct |
11 |
Correct |
3 ms |
5208 KB |
Output is correct |
12 |
Correct |
2 ms |
5208 KB |
Output is correct |
13 |
Correct |
4 ms |
5212 KB |
Output is correct |
14 |
Correct |
2 ms |
5208 KB |
Output is correct |
15 |
Correct |
2 ms |
5208 KB |
Output is correct |
16 |
Correct |
3 ms |
5208 KB |
Output is correct |
17 |
Correct |
2 ms |
5208 KB |
Output is correct |
18 |
Correct |
4 ms |
5464 KB |
Output is correct |
19 |
Correct |
3 ms |
5404 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 |
3 ms |
5208 KB |
Output is correct |
25 |
Correct |
3 ms |
5208 KB |
Output is correct |
26 |
Correct |
2 ms |
5208 KB |
Output is correct |
27 |
Correct |
2 ms |
5208 KB |
Output is correct |
28 |
Correct |
4 ms |
5216 KB |
Output is correct |
29 |
Correct |
3 ms |
5208 KB |
Output is correct |
30 |
Correct |
4 ms |
5208 KB |
Output is correct |
31 |
Correct |
3 ms |
5208 KB |
Output is correct |
32 |
Correct |
3 ms |
5164 KB |
Output is correct |
33 |
Correct |
3 ms |
5212 KB |
Output is correct |
34 |
Correct |
3 ms |
5208 KB |
Output is correct |
35 |
Correct |
2 ms |
5208 KB |
Output is correct |
36 |
Correct |
5 ms |
5464 KB |
Output is correct |
37 |
Correct |
3 ms |
5464 KB |
Output is correct |
38 |
Correct |
4 ms |
5520 KB |
Output is correct |
39 |
Correct |
3 ms |
5204 KB |
Output is correct |
40 |
Correct |
2 ms |
5208 KB |
Output is correct |
41 |
Correct |
4 ms |
5204 KB |
Output is correct |
42 |
Correct |
4 ms |
5208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
470 ms |
9560 KB |
Output is correct |
2 |
Correct |
707 ms |
13752 KB |
Output is correct |
3 |
Correct |
677 ms |
13400 KB |
Output is correct |
4 |
Correct |
664 ms |
13336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
470 ms |
9560 KB |
Output is correct |
2 |
Correct |
707 ms |
13752 KB |
Output is correct |
3 |
Correct |
677 ms |
13400 KB |
Output is correct |
4 |
Correct |
664 ms |
13336 KB |
Output is correct |
5 |
Correct |
569 ms |
9560 KB |
Output is correct |
6 |
Correct |
768 ms |
13912 KB |
Output is correct |
7 |
Correct |
703 ms |
13912 KB |
Output is correct |
8 |
Correct |
695 ms |
13648 KB |
Output is correct |
9 |
Correct |
336 ms |
5464 KB |
Output is correct |
10 |
Correct |
672 ms |
5720 KB |
Output is correct |
11 |
Correct |
654 ms |
5720 KB |
Output is correct |
12 |
Correct |
641 ms |
5720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
3 ms |
5208 KB |
Output is correct |
3 |
Correct |
3 ms |
5208 KB |
Output is correct |
4 |
Correct |
2 ms |
5208 KB |
Output is correct |
5 |
Correct |
4 ms |
5212 KB |
Output is correct |
6 |
Correct |
2 ms |
5208 KB |
Output is correct |
7 |
Correct |
2 ms |
5208 KB |
Output is correct |
8 |
Correct |
3 ms |
5208 KB |
Output is correct |
9 |
Correct |
2 ms |
5208 KB |
Output is correct |
10 |
Correct |
4 ms |
5464 KB |
Output is correct |
11 |
Correct |
3 ms |
5404 KB |
Output is correct |
12 |
Correct |
3 ms |
5208 KB |
Output is correct |
13 |
Correct |
470 ms |
9560 KB |
Output is correct |
14 |
Correct |
707 ms |
13752 KB |
Output is correct |
15 |
Correct |
677 ms |
13400 KB |
Output is correct |
16 |
Correct |
664 ms |
13336 KB |
Output is correct |
17 |
Correct |
569 ms |
9560 KB |
Output is correct |
18 |
Correct |
768 ms |
13912 KB |
Output is correct |
19 |
Correct |
703 ms |
13912 KB |
Output is correct |
20 |
Correct |
695 ms |
13648 KB |
Output is correct |
21 |
Correct |
336 ms |
5464 KB |
Output is correct |
22 |
Correct |
672 ms |
5720 KB |
Output is correct |
23 |
Correct |
654 ms |
5720 KB |
Output is correct |
24 |
Correct |
641 ms |
5720 KB |
Output is correct |
25 |
Correct |
721 ms |
19412 KB |
Output is correct |
26 |
Correct |
757 ms |
19800 KB |
Output is correct |
27 |
Correct |
795 ms |
19548 KB |
Output is correct |
28 |
Correct |
601 ms |
19280 KB |
Output is correct |
29 |
Correct |
791 ms |
41456 KB |
Output is correct |
30 |
Correct |
745 ms |
41296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4952 KB |
Output is correct |
2 |
Correct |
3 ms |
4952 KB |
Output is correct |
3 |
Correct |
3 ms |
5312 KB |
Output is correct |
4 |
Correct |
2 ms |
5208 KB |
Output is correct |
5 |
Correct |
2 ms |
5208 KB |
Output is correct |
6 |
Correct |
2 ms |
5208 KB |
Output is correct |
7 |
Correct |
2 ms |
5208 KB |
Output is correct |
8 |
Correct |
3 ms |
5208 KB |
Output is correct |
9 |
Correct |
2 ms |
4952 KB |
Output is correct |
10 |
Correct |
3 ms |
5208 KB |
Output is correct |
11 |
Correct |
3 ms |
5208 KB |
Output is correct |
12 |
Correct |
2 ms |
5208 KB |
Output is correct |
13 |
Correct |
4 ms |
5212 KB |
Output is correct |
14 |
Correct |
2 ms |
5208 KB |
Output is correct |
15 |
Correct |
2 ms |
5208 KB |
Output is correct |
16 |
Correct |
3 ms |
5208 KB |
Output is correct |
17 |
Correct |
2 ms |
5208 KB |
Output is correct |
18 |
Correct |
4 ms |
5464 KB |
Output is correct |
19 |
Correct |
3 ms |
5404 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 |
3 ms |
5208 KB |
Output is correct |
25 |
Correct |
3 ms |
5208 KB |
Output is correct |
26 |
Correct |
2 ms |
5208 KB |
Output is correct |
27 |
Correct |
2 ms |
5208 KB |
Output is correct |
28 |
Correct |
4 ms |
5216 KB |
Output is correct |
29 |
Correct |
3 ms |
5208 KB |
Output is correct |
30 |
Correct |
4 ms |
5208 KB |
Output is correct |
31 |
Correct |
3 ms |
5208 KB |
Output is correct |
32 |
Correct |
3 ms |
5164 KB |
Output is correct |
33 |
Correct |
3 ms |
5212 KB |
Output is correct |
34 |
Correct |
3 ms |
5208 KB |
Output is correct |
35 |
Correct |
2 ms |
5208 KB |
Output is correct |
36 |
Correct |
5 ms |
5464 KB |
Output is correct |
37 |
Correct |
3 ms |
5464 KB |
Output is correct |
38 |
Correct |
4 ms |
5520 KB |
Output is correct |
39 |
Correct |
3 ms |
5204 KB |
Output is correct |
40 |
Correct |
2 ms |
5208 KB |
Output is correct |
41 |
Correct |
4 ms |
5204 KB |
Output is correct |
42 |
Correct |
4 ms |
5208 KB |
Output is correct |
43 |
Correct |
497 ms |
5464 KB |
Output is correct |
44 |
Correct |
665 ms |
5720 KB |
Output is correct |
45 |
Correct |
669 ms |
5720 KB |
Output is correct |
46 |
Correct |
617 ms |
5976 KB |
Output is correct |
47 |
Correct |
670 ms |
5976 KB |
Output is correct |
48 |
Correct |
764 ms |
5976 KB |
Output is correct |
49 |
Correct |
672 ms |
5976 KB |
Output is correct |
50 |
Correct |
635 ms |
5976 KB |
Output is correct |
51 |
Correct |
640 ms |
5832 KB |
Output is correct |
52 |
Correct |
679 ms |
5932 KB |
Output is correct |
53 |
Correct |
623 ms |
6232 KB |
Output is correct |
54 |
Correct |
660 ms |
5976 KB |
Output is correct |
55 |
Correct |
653 ms |
5976 KB |
Output is correct |
56 |
Correct |
661 ms |
5720 KB |
Output is correct |
57 |
Correct |
638 ms |
5720 KB |
Output is correct |
58 |
Correct |
646 ms |
7000 KB |
Output is correct |
59 |
Correct |
635 ms |
7000 KB |
Output is correct |
60 |
Correct |
678 ms |
7000 KB |
Output is correct |
61 |
Correct |
652 ms |
5924 KB |
Output is correct |
62 |
Correct |
671 ms |
5464 KB |
Output is correct |
63 |
Correct |
667 ms |
5464 KB |
Output is correct |
64 |
Correct |
690 ms |
5720 KB |
Output is correct |
65 |
Correct |
316 ms |
5464 KB |
Output is correct |
66 |
Correct |
711 ms |
5720 KB |
Output is correct |
67 |
Correct |
642 ms |
5976 KB |
Output is correct |
68 |
Correct |
683 ms |
5976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4952 KB |
Output is correct |
2 |
Correct |
3 ms |
4952 KB |
Output is correct |
3 |
Correct |
3 ms |
5312 KB |
Output is correct |
4 |
Correct |
2 ms |
5208 KB |
Output is correct |
5 |
Correct |
2 ms |
5208 KB |
Output is correct |
6 |
Correct |
2 ms |
5208 KB |
Output is correct |
7 |
Correct |
2 ms |
5208 KB |
Output is correct |
8 |
Correct |
3 ms |
5208 KB |
Output is correct |
9 |
Correct |
2 ms |
4952 KB |
Output is correct |
10 |
Correct |
3 ms |
5208 KB |
Output is correct |
11 |
Correct |
3 ms |
5208 KB |
Output is correct |
12 |
Correct |
2 ms |
5208 KB |
Output is correct |
13 |
Correct |
4 ms |
5212 KB |
Output is correct |
14 |
Correct |
2 ms |
5208 KB |
Output is correct |
15 |
Correct |
2 ms |
5208 KB |
Output is correct |
16 |
Correct |
3 ms |
5208 KB |
Output is correct |
17 |
Correct |
2 ms |
5208 KB |
Output is correct |
18 |
Correct |
4 ms |
5464 KB |
Output is correct |
19 |
Correct |
3 ms |
5404 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 |
3 ms |
5208 KB |
Output is correct |
25 |
Correct |
3 ms |
5208 KB |
Output is correct |
26 |
Correct |
2 ms |
5208 KB |
Output is correct |
27 |
Correct |
2 ms |
5208 KB |
Output is correct |
28 |
Correct |
4 ms |
5216 KB |
Output is correct |
29 |
Correct |
3 ms |
5208 KB |
Output is correct |
30 |
Correct |
4 ms |
5208 KB |
Output is correct |
31 |
Correct |
3 ms |
5208 KB |
Output is correct |
32 |
Correct |
3 ms |
5164 KB |
Output is correct |
33 |
Correct |
3 ms |
5212 KB |
Output is correct |
34 |
Correct |
3 ms |
5208 KB |
Output is correct |
35 |
Correct |
2 ms |
5208 KB |
Output is correct |
36 |
Correct |
5 ms |
5464 KB |
Output is correct |
37 |
Correct |
3 ms |
5464 KB |
Output is correct |
38 |
Correct |
4 ms |
5520 KB |
Output is correct |
39 |
Correct |
3 ms |
5204 KB |
Output is correct |
40 |
Correct |
2 ms |
5208 KB |
Output is correct |
41 |
Correct |
4 ms |
5204 KB |
Output is correct |
42 |
Correct |
4 ms |
5208 KB |
Output is correct |
43 |
Correct |
470 ms |
9560 KB |
Output is correct |
44 |
Correct |
707 ms |
13752 KB |
Output is correct |
45 |
Correct |
677 ms |
13400 KB |
Output is correct |
46 |
Correct |
664 ms |
13336 KB |
Output is correct |
47 |
Correct |
569 ms |
9560 KB |
Output is correct |
48 |
Correct |
768 ms |
13912 KB |
Output is correct |
49 |
Correct |
703 ms |
13912 KB |
Output is correct |
50 |
Correct |
695 ms |
13648 KB |
Output is correct |
51 |
Correct |
336 ms |
5464 KB |
Output is correct |
52 |
Correct |
672 ms |
5720 KB |
Output is correct |
53 |
Correct |
654 ms |
5720 KB |
Output is correct |
54 |
Correct |
641 ms |
5720 KB |
Output is correct |
55 |
Correct |
721 ms |
19412 KB |
Output is correct |
56 |
Correct |
757 ms |
19800 KB |
Output is correct |
57 |
Correct |
795 ms |
19548 KB |
Output is correct |
58 |
Correct |
601 ms |
19280 KB |
Output is correct |
59 |
Correct |
791 ms |
41456 KB |
Output is correct |
60 |
Correct |
745 ms |
41296 KB |
Output is correct |
61 |
Correct |
497 ms |
5464 KB |
Output is correct |
62 |
Correct |
665 ms |
5720 KB |
Output is correct |
63 |
Correct |
669 ms |
5720 KB |
Output is correct |
64 |
Correct |
617 ms |
5976 KB |
Output is correct |
65 |
Correct |
670 ms |
5976 KB |
Output is correct |
66 |
Correct |
764 ms |
5976 KB |
Output is correct |
67 |
Correct |
672 ms |
5976 KB |
Output is correct |
68 |
Correct |
635 ms |
5976 KB |
Output is correct |
69 |
Correct |
640 ms |
5832 KB |
Output is correct |
70 |
Correct |
679 ms |
5932 KB |
Output is correct |
71 |
Correct |
623 ms |
6232 KB |
Output is correct |
72 |
Correct |
660 ms |
5976 KB |
Output is correct |
73 |
Correct |
653 ms |
5976 KB |
Output is correct |
74 |
Correct |
661 ms |
5720 KB |
Output is correct |
75 |
Correct |
638 ms |
5720 KB |
Output is correct |
76 |
Correct |
646 ms |
7000 KB |
Output is correct |
77 |
Correct |
635 ms |
7000 KB |
Output is correct |
78 |
Correct |
678 ms |
7000 KB |
Output is correct |
79 |
Correct |
652 ms |
5924 KB |
Output is correct |
80 |
Correct |
671 ms |
5464 KB |
Output is correct |
81 |
Correct |
667 ms |
5464 KB |
Output is correct |
82 |
Correct |
690 ms |
5720 KB |
Output is correct |
83 |
Correct |
316 ms |
5464 KB |
Output is correct |
84 |
Correct |
711 ms |
5720 KB |
Output is correct |
85 |
Correct |
642 ms |
5976 KB |
Output is correct |
86 |
Correct |
683 ms |
5976 KB |
Output is correct |
87 |
Correct |
2 ms |
4952 KB |
Output is correct |
88 |
Correct |
458 ms |
19076 KB |
Output is correct |
89 |
Correct |
762 ms |
13648 KB |
Output is correct |
90 |
Correct |
777 ms |
13936 KB |
Output is correct |
91 |
Correct |
745 ms |
20048 KB |
Output is correct |
92 |
Correct |
813 ms |
19392 KB |
Output is correct |
93 |
Correct |
804 ms |
19384 KB |
Output is correct |
94 |
Correct |
780 ms |
20164 KB |
Output is correct |
95 |
Correct |
659 ms |
20048 KB |
Output is correct |
96 |
Correct |
669 ms |
14708 KB |
Output is correct |
97 |
Correct |
724 ms |
16276 KB |
Output is correct |
98 |
Correct |
664 ms |
29380 KB |
Output is correct |
99 |
Correct |
806 ms |
19808 KB |
Output is correct |
100 |
Correct |
742 ms |
18404 KB |
Output is correct |
101 |
Correct |
765 ms |
17684 KB |
Output is correct |
102 |
Correct |
743 ms |
16240 KB |
Output is correct |
103 |
Correct |
783 ms |
41452 KB |
Output is correct |
104 |
Correct |
704 ms |
39164 KB |
Output is correct |
105 |
Correct |
731 ms |
38828 KB |
Output is correct |
106 |
Correct |
703 ms |
17896 KB |
Output is correct |
107 |
Correct |
733 ms |
16020 KB |
Output is correct |
108 |
Correct |
720 ms |
16692 KB |
Output is correct |
109 |
Correct |
704 ms |
16496 KB |
Output is correct |