#include "circuit.h"
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 1e9 + 2022;
int n, m, k, x, y, z;
int val[200005], cont[200005], cur[200005];
int seg[1'000'005], lzy[1'000'005], ps[200005];
vector<signed> par, gph[200005];
void dfs(int id) {
val[id] = id >= n ? 1 : gph[id].size();
for (auto i : gph[id]) dfs(i), val[id] = val[id] * val[i] % mod;
}
void dfs2(int id, int cur) {
if (id >= n) cont[id - n + 1] = cur;
int post[gph[id].size()+2], pre = 1;
post[gph[id].size()+1] = 1;
for (int i = gph[id].size(); i >= 1; i--) post[i] = post[i+1] * val[gph[id][i-1]] % mod;
for (int i = 1; i <= gph[id].size(); i++) {
dfs2(gph[id][i-1], cur * pre % mod * post[i+1] % mod);
pre = pre * val[gph[id][i-1]] % mod;
}
}
void push(int id, int l, int r) {
if (!lzy[id]) return;
lzy[id] = 0;
int mid = (l + r) / 2;
seg[id * 2] = ps[mid] - ps[l-1] - seg[id * 2];
seg[id * 2 + 1] = ps[r] - ps[mid] - seg[id * 2 + 1];
lzy[2 * id] ^= 1;
lzy[2 * id + 1] ^= 1;
}
void upd(int t1, int t2, int id = 1, int l = 1, int r = 100000) {
push(id, l, r);
if (r < t1 || t2 < l) return;
if (t1 <= l && r <= t2) {
seg[id] = ps[r] - ps[l-1] - seg[id];
lzy[id] ^= 1;
return;
}
int mid = (l + r) / 2;
upd(t1, t2, id * 2, l, mid), upd(t1, t2, id * 2 + 1, mid + 1, r);
seg[id] = (seg[id * 2] + seg[id * 2 + 1]) % mod;
}
void init(signed N, signed M, std::vector<signed> P, std::vector<signed> A) {
n = N, m = M, par = P;
for (int i = 1; i < n + m; i++) gph[P[i]].push_back(i);
for (int i = n; i < n + m; i++) cur[i] = A[i-n];
dfs(0);
dfs2(0, 1);
for (int i = 1; i <= m; i++) ps[i] = (ps[i-1] + cont[i]) % mod;
for (int i = 1; i <= m; i++) if (A[i-1]) upd(i, i);
}
signed count_ways(signed L, signed R) {
upd(L - n + 1, R - n + 1);
return (seg[1] % mod + mod) % mod;
}
Compilation message
circuit.cpp: In function 'void dfs2(long long int, long long int)':
circuit.cpp:22:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for (int i = 1; i <= gph[id].size(); i++) {
| ~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5072 KB |
Output is correct |
2 |
Correct |
3 ms |
5080 KB |
Output is correct |
3 |
Correct |
3 ms |
5200 KB |
Output is correct |
4 |
Correct |
3 ms |
5072 KB |
Output is correct |
5 |
Correct |
3 ms |
5244 KB |
Output is correct |
6 |
Correct |
3 ms |
5200 KB |
Output is correct |
7 |
Correct |
3 ms |
5200 KB |
Output is correct |
8 |
Correct |
3 ms |
5200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5080 KB |
Output is correct |
2 |
Correct |
3 ms |
5072 KB |
Output is correct |
3 |
Correct |
3 ms |
5200 KB |
Output is correct |
4 |
Correct |
3 ms |
5200 KB |
Output is correct |
5 |
Correct |
3 ms |
5200 KB |
Output is correct |
6 |
Correct |
3 ms |
5200 KB |
Output is correct |
7 |
Correct |
3 ms |
5200 KB |
Output is correct |
8 |
Correct |
3 ms |
5244 KB |
Output is correct |
9 |
Correct |
3 ms |
5200 KB |
Output is correct |
10 |
Correct |
3 ms |
5328 KB |
Output is correct |
11 |
Correct |
3 ms |
5404 KB |
Output is correct |
12 |
Correct |
4 ms |
5200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5072 KB |
Output is correct |
2 |
Correct |
3 ms |
5080 KB |
Output is correct |
3 |
Correct |
3 ms |
5200 KB |
Output is correct |
4 |
Correct |
3 ms |
5072 KB |
Output is correct |
5 |
Correct |
3 ms |
5244 KB |
Output is correct |
6 |
Correct |
3 ms |
5200 KB |
Output is correct |
7 |
Correct |
3 ms |
5200 KB |
Output is correct |
8 |
Correct |
3 ms |
5200 KB |
Output is correct |
9 |
Correct |
3 ms |
5080 KB |
Output is correct |
10 |
Correct |
3 ms |
5072 KB |
Output is correct |
11 |
Correct |
3 ms |
5200 KB |
Output is correct |
12 |
Correct |
3 ms |
5200 KB |
Output is correct |
13 |
Correct |
3 ms |
5200 KB |
Output is correct |
14 |
Correct |
3 ms |
5200 KB |
Output is correct |
15 |
Correct |
3 ms |
5200 KB |
Output is correct |
16 |
Correct |
3 ms |
5244 KB |
Output is correct |
17 |
Correct |
3 ms |
5200 KB |
Output is correct |
18 |
Correct |
3 ms |
5328 KB |
Output is correct |
19 |
Correct |
3 ms |
5404 KB |
Output is correct |
20 |
Correct |
4 ms |
5200 KB |
Output is correct |
21 |
Correct |
3 ms |
5200 KB |
Output is correct |
22 |
Correct |
3 ms |
5200 KB |
Output is correct |
23 |
Correct |
3 ms |
5156 KB |
Output is correct |
24 |
Correct |
3 ms |
5200 KB |
Output is correct |
25 |
Correct |
3 ms |
5200 KB |
Output is correct |
26 |
Correct |
3 ms |
5200 KB |
Output is correct |
27 |
Correct |
4 ms |
5200 KB |
Output is correct |
28 |
Correct |
3 ms |
5200 KB |
Output is correct |
29 |
Correct |
3 ms |
5252 KB |
Output is correct |
30 |
Correct |
3 ms |
5200 KB |
Output is correct |
31 |
Correct |
3 ms |
5200 KB |
Output is correct |
32 |
Correct |
3 ms |
5200 KB |
Output is correct |
33 |
Correct |
3 ms |
5200 KB |
Output is correct |
34 |
Correct |
3 ms |
5200 KB |
Output is correct |
35 |
Correct |
3 ms |
5200 KB |
Output is correct |
36 |
Correct |
3 ms |
5328 KB |
Output is correct |
37 |
Correct |
3 ms |
5328 KB |
Output is correct |
38 |
Correct |
3 ms |
5436 KB |
Output is correct |
39 |
Correct |
3 ms |
5216 KB |
Output is correct |
40 |
Correct |
3 ms |
5200 KB |
Output is correct |
41 |
Correct |
3 ms |
5200 KB |
Output is correct |
42 |
Correct |
3 ms |
5128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
477 ms |
10872 KB |
Output is correct |
2 |
Correct |
928 ms |
16788 KB |
Output is correct |
3 |
Correct |
784 ms |
16776 KB |
Output is correct |
4 |
Correct |
886 ms |
16016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
477 ms |
10872 KB |
Output is correct |
2 |
Correct |
928 ms |
16788 KB |
Output is correct |
3 |
Correct |
784 ms |
16776 KB |
Output is correct |
4 |
Correct |
886 ms |
16016 KB |
Output is correct |
5 |
Correct |
732 ms |
10880 KB |
Output is correct |
6 |
Correct |
933 ms |
16724 KB |
Output is correct |
7 |
Correct |
960 ms |
16388 KB |
Output is correct |
8 |
Correct |
901 ms |
16772 KB |
Output is correct |
9 |
Correct |
445 ms |
5456 KB |
Output is correct |
10 |
Correct |
844 ms |
5856 KB |
Output is correct |
11 |
Correct |
831 ms |
5840 KB |
Output is correct |
12 |
Correct |
767 ms |
5840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5080 KB |
Output is correct |
2 |
Correct |
3 ms |
5072 KB |
Output is correct |
3 |
Correct |
3 ms |
5200 KB |
Output is correct |
4 |
Correct |
3 ms |
5200 KB |
Output is correct |
5 |
Correct |
3 ms |
5200 KB |
Output is correct |
6 |
Correct |
3 ms |
5200 KB |
Output is correct |
7 |
Correct |
3 ms |
5200 KB |
Output is correct |
8 |
Correct |
3 ms |
5244 KB |
Output is correct |
9 |
Correct |
3 ms |
5200 KB |
Output is correct |
10 |
Correct |
3 ms |
5328 KB |
Output is correct |
11 |
Correct |
3 ms |
5404 KB |
Output is correct |
12 |
Correct |
4 ms |
5200 KB |
Output is correct |
13 |
Correct |
477 ms |
10872 KB |
Output is correct |
14 |
Correct |
928 ms |
16788 KB |
Output is correct |
15 |
Correct |
784 ms |
16776 KB |
Output is correct |
16 |
Correct |
886 ms |
16016 KB |
Output is correct |
17 |
Correct |
732 ms |
10880 KB |
Output is correct |
18 |
Correct |
933 ms |
16724 KB |
Output is correct |
19 |
Correct |
960 ms |
16388 KB |
Output is correct |
20 |
Correct |
901 ms |
16772 KB |
Output is correct |
21 |
Correct |
445 ms |
5456 KB |
Output is correct |
22 |
Correct |
844 ms |
5856 KB |
Output is correct |
23 |
Correct |
831 ms |
5840 KB |
Output is correct |
24 |
Correct |
767 ms |
5840 KB |
Output is correct |
25 |
Correct |
990 ms |
22568 KB |
Output is correct |
26 |
Correct |
923 ms |
22772 KB |
Output is correct |
27 |
Correct |
1024 ms |
22232 KB |
Output is correct |
28 |
Correct |
684 ms |
22856 KB |
Output is correct |
29 |
Correct |
863 ms |
35328 KB |
Output is correct |
30 |
Correct |
955 ms |
35380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5072 KB |
Output is correct |
2 |
Correct |
3 ms |
5080 KB |
Output is correct |
3 |
Correct |
3 ms |
5200 KB |
Output is correct |
4 |
Correct |
3 ms |
5072 KB |
Output is correct |
5 |
Correct |
3 ms |
5244 KB |
Output is correct |
6 |
Correct |
3 ms |
5200 KB |
Output is correct |
7 |
Correct |
3 ms |
5200 KB |
Output is correct |
8 |
Correct |
3 ms |
5200 KB |
Output is correct |
9 |
Correct |
3 ms |
5080 KB |
Output is correct |
10 |
Correct |
3 ms |
5072 KB |
Output is correct |
11 |
Correct |
3 ms |
5200 KB |
Output is correct |
12 |
Correct |
3 ms |
5200 KB |
Output is correct |
13 |
Correct |
3 ms |
5200 KB |
Output is correct |
14 |
Correct |
3 ms |
5200 KB |
Output is correct |
15 |
Correct |
3 ms |
5200 KB |
Output is correct |
16 |
Correct |
3 ms |
5244 KB |
Output is correct |
17 |
Correct |
3 ms |
5200 KB |
Output is correct |
18 |
Correct |
3 ms |
5328 KB |
Output is correct |
19 |
Correct |
3 ms |
5404 KB |
Output is correct |
20 |
Correct |
4 ms |
5200 KB |
Output is correct |
21 |
Correct |
3 ms |
5200 KB |
Output is correct |
22 |
Correct |
3 ms |
5200 KB |
Output is correct |
23 |
Correct |
3 ms |
5156 KB |
Output is correct |
24 |
Correct |
3 ms |
5200 KB |
Output is correct |
25 |
Correct |
3 ms |
5200 KB |
Output is correct |
26 |
Correct |
3 ms |
5200 KB |
Output is correct |
27 |
Correct |
4 ms |
5200 KB |
Output is correct |
28 |
Correct |
3 ms |
5200 KB |
Output is correct |
29 |
Correct |
3 ms |
5252 KB |
Output is correct |
30 |
Correct |
3 ms |
5200 KB |
Output is correct |
31 |
Correct |
3 ms |
5200 KB |
Output is correct |
32 |
Correct |
3 ms |
5200 KB |
Output is correct |
33 |
Correct |
3 ms |
5200 KB |
Output is correct |
34 |
Correct |
3 ms |
5200 KB |
Output is correct |
35 |
Correct |
3 ms |
5200 KB |
Output is correct |
36 |
Correct |
3 ms |
5328 KB |
Output is correct |
37 |
Correct |
3 ms |
5328 KB |
Output is correct |
38 |
Correct |
3 ms |
5436 KB |
Output is correct |
39 |
Correct |
3 ms |
5216 KB |
Output is correct |
40 |
Correct |
3 ms |
5200 KB |
Output is correct |
41 |
Correct |
3 ms |
5200 KB |
Output is correct |
42 |
Correct |
3 ms |
5128 KB |
Output is correct |
43 |
Correct |
556 ms |
5584 KB |
Output is correct |
44 |
Correct |
853 ms |
5584 KB |
Output is correct |
45 |
Correct |
735 ms |
5632 KB |
Output is correct |
46 |
Correct |
696 ms |
5932 KB |
Output is correct |
47 |
Correct |
905 ms |
5968 KB |
Output is correct |
48 |
Correct |
853 ms |
5968 KB |
Output is correct |
49 |
Correct |
748 ms |
6040 KB |
Output is correct |
50 |
Correct |
846 ms |
5828 KB |
Output is correct |
51 |
Correct |
811 ms |
5840 KB |
Output is correct |
52 |
Correct |
919 ms |
5840 KB |
Output is correct |
53 |
Correct |
757 ms |
5840 KB |
Output is correct |
54 |
Correct |
816 ms |
6000 KB |
Output is correct |
55 |
Correct |
825 ms |
5896 KB |
Output is correct |
56 |
Correct |
835 ms |
5840 KB |
Output is correct |
57 |
Correct |
956 ms |
5712 KB |
Output is correct |
58 |
Correct |
885 ms |
6608 KB |
Output is correct |
59 |
Correct |
750 ms |
6752 KB |
Output is correct |
60 |
Correct |
840 ms |
6744 KB |
Output is correct |
61 |
Correct |
790 ms |
5712 KB |
Output is correct |
62 |
Correct |
861 ms |
5584 KB |
Output is correct |
63 |
Correct |
907 ms |
5680 KB |
Output is correct |
64 |
Correct |
780 ms |
5808 KB |
Output is correct |
65 |
Correct |
308 ms |
5456 KB |
Output is correct |
66 |
Correct |
891 ms |
5840 KB |
Output is correct |
67 |
Correct |
907 ms |
5880 KB |
Output is correct |
68 |
Correct |
806 ms |
5856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5072 KB |
Output is correct |
2 |
Correct |
3 ms |
5080 KB |
Output is correct |
3 |
Correct |
3 ms |
5200 KB |
Output is correct |
4 |
Correct |
3 ms |
5072 KB |
Output is correct |
5 |
Correct |
3 ms |
5244 KB |
Output is correct |
6 |
Correct |
3 ms |
5200 KB |
Output is correct |
7 |
Correct |
3 ms |
5200 KB |
Output is correct |
8 |
Correct |
3 ms |
5200 KB |
Output is correct |
9 |
Correct |
3 ms |
5080 KB |
Output is correct |
10 |
Correct |
3 ms |
5072 KB |
Output is correct |
11 |
Correct |
3 ms |
5200 KB |
Output is correct |
12 |
Correct |
3 ms |
5200 KB |
Output is correct |
13 |
Correct |
3 ms |
5200 KB |
Output is correct |
14 |
Correct |
3 ms |
5200 KB |
Output is correct |
15 |
Correct |
3 ms |
5200 KB |
Output is correct |
16 |
Correct |
3 ms |
5244 KB |
Output is correct |
17 |
Correct |
3 ms |
5200 KB |
Output is correct |
18 |
Correct |
3 ms |
5328 KB |
Output is correct |
19 |
Correct |
3 ms |
5404 KB |
Output is correct |
20 |
Correct |
4 ms |
5200 KB |
Output is correct |
21 |
Correct |
3 ms |
5200 KB |
Output is correct |
22 |
Correct |
3 ms |
5200 KB |
Output is correct |
23 |
Correct |
3 ms |
5156 KB |
Output is correct |
24 |
Correct |
3 ms |
5200 KB |
Output is correct |
25 |
Correct |
3 ms |
5200 KB |
Output is correct |
26 |
Correct |
3 ms |
5200 KB |
Output is correct |
27 |
Correct |
4 ms |
5200 KB |
Output is correct |
28 |
Correct |
3 ms |
5200 KB |
Output is correct |
29 |
Correct |
3 ms |
5252 KB |
Output is correct |
30 |
Correct |
3 ms |
5200 KB |
Output is correct |
31 |
Correct |
3 ms |
5200 KB |
Output is correct |
32 |
Correct |
3 ms |
5200 KB |
Output is correct |
33 |
Correct |
3 ms |
5200 KB |
Output is correct |
34 |
Correct |
3 ms |
5200 KB |
Output is correct |
35 |
Correct |
3 ms |
5200 KB |
Output is correct |
36 |
Correct |
3 ms |
5328 KB |
Output is correct |
37 |
Correct |
3 ms |
5328 KB |
Output is correct |
38 |
Correct |
3 ms |
5436 KB |
Output is correct |
39 |
Correct |
3 ms |
5216 KB |
Output is correct |
40 |
Correct |
3 ms |
5200 KB |
Output is correct |
41 |
Correct |
3 ms |
5200 KB |
Output is correct |
42 |
Correct |
3 ms |
5128 KB |
Output is correct |
43 |
Correct |
477 ms |
10872 KB |
Output is correct |
44 |
Correct |
928 ms |
16788 KB |
Output is correct |
45 |
Correct |
784 ms |
16776 KB |
Output is correct |
46 |
Correct |
886 ms |
16016 KB |
Output is correct |
47 |
Correct |
732 ms |
10880 KB |
Output is correct |
48 |
Correct |
933 ms |
16724 KB |
Output is correct |
49 |
Correct |
960 ms |
16388 KB |
Output is correct |
50 |
Correct |
901 ms |
16772 KB |
Output is correct |
51 |
Correct |
445 ms |
5456 KB |
Output is correct |
52 |
Correct |
844 ms |
5856 KB |
Output is correct |
53 |
Correct |
831 ms |
5840 KB |
Output is correct |
54 |
Correct |
767 ms |
5840 KB |
Output is correct |
55 |
Correct |
990 ms |
22568 KB |
Output is correct |
56 |
Correct |
923 ms |
22772 KB |
Output is correct |
57 |
Correct |
1024 ms |
22232 KB |
Output is correct |
58 |
Correct |
684 ms |
22856 KB |
Output is correct |
59 |
Correct |
863 ms |
35328 KB |
Output is correct |
60 |
Correct |
955 ms |
35380 KB |
Output is correct |
61 |
Correct |
556 ms |
5584 KB |
Output is correct |
62 |
Correct |
853 ms |
5584 KB |
Output is correct |
63 |
Correct |
735 ms |
5632 KB |
Output is correct |
64 |
Correct |
696 ms |
5932 KB |
Output is correct |
65 |
Correct |
905 ms |
5968 KB |
Output is correct |
66 |
Correct |
853 ms |
5968 KB |
Output is correct |
67 |
Correct |
748 ms |
6040 KB |
Output is correct |
68 |
Correct |
846 ms |
5828 KB |
Output is correct |
69 |
Correct |
811 ms |
5840 KB |
Output is correct |
70 |
Correct |
919 ms |
5840 KB |
Output is correct |
71 |
Correct |
757 ms |
5840 KB |
Output is correct |
72 |
Correct |
816 ms |
6000 KB |
Output is correct |
73 |
Correct |
825 ms |
5896 KB |
Output is correct |
74 |
Correct |
835 ms |
5840 KB |
Output is correct |
75 |
Correct |
956 ms |
5712 KB |
Output is correct |
76 |
Correct |
885 ms |
6608 KB |
Output is correct |
77 |
Correct |
750 ms |
6752 KB |
Output is correct |
78 |
Correct |
840 ms |
6744 KB |
Output is correct |
79 |
Correct |
790 ms |
5712 KB |
Output is correct |
80 |
Correct |
861 ms |
5584 KB |
Output is correct |
81 |
Correct |
907 ms |
5680 KB |
Output is correct |
82 |
Correct |
780 ms |
5808 KB |
Output is correct |
83 |
Correct |
308 ms |
5456 KB |
Output is correct |
84 |
Correct |
891 ms |
5840 KB |
Output is correct |
85 |
Correct |
907 ms |
5880 KB |
Output is correct |
86 |
Correct |
806 ms |
5856 KB |
Output is correct |
87 |
Correct |
2 ms |
5072 KB |
Output is correct |
88 |
Correct |
622 ms |
20336 KB |
Output is correct |
89 |
Correct |
925 ms |
15232 KB |
Output is correct |
90 |
Correct |
819 ms |
15688 KB |
Output is correct |
91 |
Correct |
951 ms |
22984 KB |
Output is correct |
92 |
Correct |
998 ms |
22964 KB |
Output is correct |
93 |
Correct |
788 ms |
22516 KB |
Output is correct |
94 |
Correct |
966 ms |
22988 KB |
Output is correct |
95 |
Correct |
885 ms |
18816 KB |
Output is correct |
96 |
Correct |
850 ms |
19008 KB |
Output is correct |
97 |
Correct |
903 ms |
19064 KB |
Output is correct |
98 |
Correct |
939 ms |
22652 KB |
Output is correct |
99 |
Correct |
1002 ms |
22784 KB |
Output is correct |
100 |
Correct |
1055 ms |
20312 KB |
Output is correct |
101 |
Correct |
1042 ms |
19656 KB |
Output is correct |
102 |
Correct |
1000 ms |
18300 KB |
Output is correct |
103 |
Correct |
903 ms |
35456 KB |
Output is correct |
104 |
Correct |
965 ms |
36608 KB |
Output is correct |
105 |
Correct |
1039 ms |
36592 KB |
Output is correct |
106 |
Correct |
635 ms |
17096 KB |
Output is correct |
107 |
Correct |
1054 ms |
15616 KB |
Output is correct |
108 |
Correct |
1053 ms |
16496 KB |
Output is correct |
109 |
Correct |
1062 ms |
18376 KB |
Output is correct |