// Be name khoda //
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define debug(x) cerr << "(" << (#x) << "): " << (x) << endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
const int mod = 1000002022;
const int maxn5 = 2e5 + 10;
const int maxnt = 1e6 + 10;
vector <int> adj[maxn5];
int n, m;
ll val[maxn5], all[maxn5];
void fix(int &a){
if(a >= mod)
a -= mod;
}
namespace seg{
int sum[maxnt][2];
bool lazy[maxnt];
void toggle(int l, int r, int lq, int rq, int v){
if(rq <= l || r <= lq)
return;
if(lq <= l && r <= rq){
lazy[v] ^= 1;
swap(sum[v][0], sum[v][1]);
return;
}
int mid = (l + r) >> 1;
toggle(l, mid, lq, rq, v * 2);
toggle(mid, r, lq, rq, v * 2 + 1);
fix(sum[v][0] = sum[v * 2][0] + sum[v * 2 + 1][0]);
fix(sum[v][1] = sum[v * 2][1] + sum[v * 2 + 1][1]);
if(lazy[v])
swap(sum[v][0], sum[v][1]);
return;
debug(l);
debug(r);
debug(lq);
debug(rq);
debug(sum[v][0]);
debug(sum[v][1]);
debug(lazy[v]);
debug(sum[v * 2 + 1][0]);
}
void build(int l, int r, int v){
if(r - l == 1){
sum[v][0] = 0;
sum[v][1] = val[l + n];
return;
}
int mid = (l + r) >> 1;
build(l, mid, v * 2);
build(mid, r, v * 2 + 1);
fix(sum[v][0] = sum[v * 2][0] + sum[v * 2 + 1][0]);
fix(sum[v][1] = sum[v * 2][1] + sum[v * 2 + 1][1]);
}
}
void dfs2(int v){
ll x = val[v];
for(auto u : adj[v]){
val[u] = x;
x = x * all[u] % mod;
}
x = 1;
reverse(all(adj[v]));
for(auto u : adj[v]){
val[u] = val[u] * x % mod;
dfs2(u);
x = x * all[u] % mod;
}
return;
debug(v);
debug(all[v]);
debug(val[v]);
debug(val[6]);
}
void dfs1(int v){
all[v] = max(1, int(adj[v].size()));
for(auto u : adj[v]){
dfs1(u);
all[v] = all[v] * all[u] % mod;
}
}
void init(int N, int M, std::vector<int> p, std::vector<int> a) {
n = N;
m = M;
for(int i = 1; i < n + m; i++)
adj[p[i]].pb(i);
val[0] = 1;
dfs1(0);
dfs2(0);
seg::build(0, m, 1);
for(int i = 0; i < m; i++){
//debug(i);
//debug(val[i + n]);
if(a[i])
seg::toggle(0, m, i, i + 1, 1);
}
}
int count_ways(int l, int r) {
l -= n;
r -= n;
seg::toggle(0, m, l, r + 1, 1);
return seg::sum[1][0];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
5072 KB |
Output is correct |
4 |
Correct |
2 ms |
5072 KB |
Output is correct |
5 |
Correct |
3 ms |
5072 KB |
Output is correct |
6 |
Correct |
3 ms |
5072 KB |
Output is correct |
7 |
Correct |
2 ms |
5072 KB |
Output is correct |
8 |
Correct |
3 ms |
5072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
5072 KB |
Output is correct |
4 |
Correct |
2 ms |
5072 KB |
Output is correct |
5 |
Correct |
3 ms |
5072 KB |
Output is correct |
6 |
Correct |
2 ms |
5072 KB |
Output is correct |
7 |
Correct |
3 ms |
5072 KB |
Output is correct |
8 |
Correct |
3 ms |
5072 KB |
Output is correct |
9 |
Correct |
3 ms |
5072 KB |
Output is correct |
10 |
Correct |
3 ms |
5072 KB |
Output is correct |
11 |
Correct |
3 ms |
5072 KB |
Output is correct |
12 |
Correct |
2 ms |
5072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
5072 KB |
Output is correct |
4 |
Correct |
2 ms |
5072 KB |
Output is correct |
5 |
Correct |
3 ms |
5072 KB |
Output is correct |
6 |
Correct |
3 ms |
5072 KB |
Output is correct |
7 |
Correct |
2 ms |
5072 KB |
Output is correct |
8 |
Correct |
3 ms |
5072 KB |
Output is correct |
9 |
Correct |
2 ms |
4944 KB |
Output is correct |
10 |
Correct |
3 ms |
4944 KB |
Output is correct |
11 |
Correct |
3 ms |
5072 KB |
Output is correct |
12 |
Correct |
2 ms |
5072 KB |
Output is correct |
13 |
Correct |
3 ms |
5072 KB |
Output is correct |
14 |
Correct |
2 ms |
5072 KB |
Output is correct |
15 |
Correct |
3 ms |
5072 KB |
Output is correct |
16 |
Correct |
3 ms |
5072 KB |
Output is correct |
17 |
Correct |
3 ms |
5072 KB |
Output is correct |
18 |
Correct |
3 ms |
5072 KB |
Output is correct |
19 |
Correct |
3 ms |
5072 KB |
Output is correct |
20 |
Correct |
2 ms |
5072 KB |
Output is correct |
21 |
Correct |
3 ms |
5072 KB |
Output is correct |
22 |
Correct |
3 ms |
5048 KB |
Output is correct |
23 |
Correct |
2 ms |
5072 KB |
Output is correct |
24 |
Correct |
3 ms |
5072 KB |
Output is correct |
25 |
Correct |
3 ms |
5084 KB |
Output is correct |
26 |
Correct |
3 ms |
5072 KB |
Output is correct |
27 |
Correct |
3 ms |
5072 KB |
Output is correct |
28 |
Correct |
3 ms |
5072 KB |
Output is correct |
29 |
Correct |
3 ms |
5072 KB |
Output is correct |
30 |
Correct |
2 ms |
5072 KB |
Output is correct |
31 |
Correct |
2 ms |
5072 KB |
Output is correct |
32 |
Correct |
3 ms |
5072 KB |
Output is correct |
33 |
Correct |
3 ms |
5072 KB |
Output is correct |
34 |
Correct |
3 ms |
5072 KB |
Output is correct |
35 |
Correct |
2 ms |
5072 KB |
Output is correct |
36 |
Correct |
3 ms |
5072 KB |
Output is correct |
37 |
Correct |
3 ms |
5204 KB |
Output is correct |
38 |
Correct |
3 ms |
5200 KB |
Output is correct |
39 |
Correct |
3 ms |
5072 KB |
Output is correct |
40 |
Correct |
3 ms |
5072 KB |
Output is correct |
41 |
Correct |
3 ms |
5072 KB |
Output is correct |
42 |
Correct |
3 ms |
5072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
576 ms |
8392 KB |
Output is correct |
2 |
Correct |
720 ms |
11648 KB |
Output is correct |
3 |
Correct |
782 ms |
11688 KB |
Output is correct |
4 |
Correct |
501 ms |
11660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
576 ms |
8392 KB |
Output is correct |
2 |
Correct |
720 ms |
11648 KB |
Output is correct |
3 |
Correct |
782 ms |
11688 KB |
Output is correct |
4 |
Correct |
501 ms |
11660 KB |
Output is correct |
5 |
Correct |
673 ms |
8356 KB |
Output is correct |
6 |
Correct |
726 ms |
11680 KB |
Output is correct |
7 |
Correct |
704 ms |
11652 KB |
Output is correct |
8 |
Correct |
717 ms |
11664 KB |
Output is correct |
9 |
Correct |
347 ms |
5132 KB |
Output is correct |
10 |
Correct |
806 ms |
5392 KB |
Output is correct |
11 |
Correct |
713 ms |
5368 KB |
Output is correct |
12 |
Correct |
623 ms |
5372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
5072 KB |
Output is correct |
4 |
Correct |
2 ms |
5072 KB |
Output is correct |
5 |
Correct |
3 ms |
5072 KB |
Output is correct |
6 |
Correct |
2 ms |
5072 KB |
Output is correct |
7 |
Correct |
3 ms |
5072 KB |
Output is correct |
8 |
Correct |
3 ms |
5072 KB |
Output is correct |
9 |
Correct |
3 ms |
5072 KB |
Output is correct |
10 |
Correct |
3 ms |
5072 KB |
Output is correct |
11 |
Correct |
3 ms |
5072 KB |
Output is correct |
12 |
Correct |
2 ms |
5072 KB |
Output is correct |
13 |
Correct |
576 ms |
8392 KB |
Output is correct |
14 |
Correct |
720 ms |
11648 KB |
Output is correct |
15 |
Correct |
782 ms |
11688 KB |
Output is correct |
16 |
Correct |
501 ms |
11660 KB |
Output is correct |
17 |
Correct |
673 ms |
8356 KB |
Output is correct |
18 |
Correct |
726 ms |
11680 KB |
Output is correct |
19 |
Correct |
704 ms |
11652 KB |
Output is correct |
20 |
Correct |
717 ms |
11664 KB |
Output is correct |
21 |
Correct |
347 ms |
5132 KB |
Output is correct |
22 |
Correct |
806 ms |
5392 KB |
Output is correct |
23 |
Correct |
713 ms |
5368 KB |
Output is correct |
24 |
Correct |
623 ms |
5372 KB |
Output is correct |
25 |
Correct |
723 ms |
15752 KB |
Output is correct |
26 |
Correct |
866 ms |
15772 KB |
Output is correct |
27 |
Correct |
734 ms |
15752 KB |
Output is correct |
28 |
Correct |
622 ms |
15792 KB |
Output is correct |
29 |
Correct |
892 ms |
22024 KB |
Output is correct |
30 |
Correct |
632 ms |
22088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
5072 KB |
Output is correct |
4 |
Correct |
2 ms |
5072 KB |
Output is correct |
5 |
Correct |
3 ms |
5072 KB |
Output is correct |
6 |
Correct |
3 ms |
5072 KB |
Output is correct |
7 |
Correct |
2 ms |
5072 KB |
Output is correct |
8 |
Correct |
3 ms |
5072 KB |
Output is correct |
9 |
Correct |
2 ms |
4944 KB |
Output is correct |
10 |
Correct |
3 ms |
4944 KB |
Output is correct |
11 |
Correct |
3 ms |
5072 KB |
Output is correct |
12 |
Correct |
2 ms |
5072 KB |
Output is correct |
13 |
Correct |
3 ms |
5072 KB |
Output is correct |
14 |
Correct |
2 ms |
5072 KB |
Output is correct |
15 |
Correct |
3 ms |
5072 KB |
Output is correct |
16 |
Correct |
3 ms |
5072 KB |
Output is correct |
17 |
Correct |
3 ms |
5072 KB |
Output is correct |
18 |
Correct |
3 ms |
5072 KB |
Output is correct |
19 |
Correct |
3 ms |
5072 KB |
Output is correct |
20 |
Correct |
2 ms |
5072 KB |
Output is correct |
21 |
Correct |
3 ms |
5072 KB |
Output is correct |
22 |
Correct |
3 ms |
5048 KB |
Output is correct |
23 |
Correct |
2 ms |
5072 KB |
Output is correct |
24 |
Correct |
3 ms |
5072 KB |
Output is correct |
25 |
Correct |
3 ms |
5084 KB |
Output is correct |
26 |
Correct |
3 ms |
5072 KB |
Output is correct |
27 |
Correct |
3 ms |
5072 KB |
Output is correct |
28 |
Correct |
3 ms |
5072 KB |
Output is correct |
29 |
Correct |
3 ms |
5072 KB |
Output is correct |
30 |
Correct |
2 ms |
5072 KB |
Output is correct |
31 |
Correct |
2 ms |
5072 KB |
Output is correct |
32 |
Correct |
3 ms |
5072 KB |
Output is correct |
33 |
Correct |
3 ms |
5072 KB |
Output is correct |
34 |
Correct |
3 ms |
5072 KB |
Output is correct |
35 |
Correct |
2 ms |
5072 KB |
Output is correct |
36 |
Correct |
3 ms |
5072 KB |
Output is correct |
37 |
Correct |
3 ms |
5204 KB |
Output is correct |
38 |
Correct |
3 ms |
5200 KB |
Output is correct |
39 |
Correct |
3 ms |
5072 KB |
Output is correct |
40 |
Correct |
3 ms |
5072 KB |
Output is correct |
41 |
Correct |
3 ms |
5072 KB |
Output is correct |
42 |
Correct |
3 ms |
5072 KB |
Output is correct |
43 |
Correct |
420 ms |
5328 KB |
Output is correct |
44 |
Correct |
685 ms |
5328 KB |
Output is correct |
45 |
Correct |
626 ms |
5260 KB |
Output is correct |
46 |
Correct |
539 ms |
5516 KB |
Output is correct |
47 |
Correct |
709 ms |
5584 KB |
Output is correct |
48 |
Correct |
685 ms |
5576 KB |
Output is correct |
49 |
Correct |
597 ms |
5512 KB |
Output is correct |
50 |
Correct |
619 ms |
5584 KB |
Output is correct |
51 |
Correct |
771 ms |
5328 KB |
Output is correct |
52 |
Correct |
681 ms |
5260 KB |
Output is correct |
53 |
Correct |
541 ms |
5584 KB |
Output is correct |
54 |
Correct |
819 ms |
5520 KB |
Output is correct |
55 |
Correct |
585 ms |
5392 KB |
Output is correct |
56 |
Correct |
826 ms |
5372 KB |
Output is correct |
57 |
Correct |
665 ms |
5260 KB |
Output is correct |
58 |
Correct |
625 ms |
5768 KB |
Output is correct |
59 |
Correct |
770 ms |
5956 KB |
Output is correct |
60 |
Correct |
725 ms |
5956 KB |
Output is correct |
61 |
Correct |
722 ms |
5456 KB |
Output is correct |
62 |
Correct |
717 ms |
5260 KB |
Output is correct |
63 |
Correct |
682 ms |
5200 KB |
Output is correct |
64 |
Correct |
535 ms |
5328 KB |
Output is correct |
65 |
Correct |
331 ms |
5200 KB |
Output is correct |
66 |
Correct |
768 ms |
5388 KB |
Output is correct |
67 |
Correct |
647 ms |
5328 KB |
Output is correct |
68 |
Correct |
644 ms |
5328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
5072 KB |
Output is correct |
4 |
Correct |
2 ms |
5072 KB |
Output is correct |
5 |
Correct |
3 ms |
5072 KB |
Output is correct |
6 |
Correct |
3 ms |
5072 KB |
Output is correct |
7 |
Correct |
2 ms |
5072 KB |
Output is correct |
8 |
Correct |
3 ms |
5072 KB |
Output is correct |
9 |
Correct |
2 ms |
4944 KB |
Output is correct |
10 |
Correct |
3 ms |
4944 KB |
Output is correct |
11 |
Correct |
3 ms |
5072 KB |
Output is correct |
12 |
Correct |
2 ms |
5072 KB |
Output is correct |
13 |
Correct |
3 ms |
5072 KB |
Output is correct |
14 |
Correct |
2 ms |
5072 KB |
Output is correct |
15 |
Correct |
3 ms |
5072 KB |
Output is correct |
16 |
Correct |
3 ms |
5072 KB |
Output is correct |
17 |
Correct |
3 ms |
5072 KB |
Output is correct |
18 |
Correct |
3 ms |
5072 KB |
Output is correct |
19 |
Correct |
3 ms |
5072 KB |
Output is correct |
20 |
Correct |
2 ms |
5072 KB |
Output is correct |
21 |
Correct |
3 ms |
5072 KB |
Output is correct |
22 |
Correct |
3 ms |
5048 KB |
Output is correct |
23 |
Correct |
2 ms |
5072 KB |
Output is correct |
24 |
Correct |
3 ms |
5072 KB |
Output is correct |
25 |
Correct |
3 ms |
5084 KB |
Output is correct |
26 |
Correct |
3 ms |
5072 KB |
Output is correct |
27 |
Correct |
3 ms |
5072 KB |
Output is correct |
28 |
Correct |
3 ms |
5072 KB |
Output is correct |
29 |
Correct |
3 ms |
5072 KB |
Output is correct |
30 |
Correct |
2 ms |
5072 KB |
Output is correct |
31 |
Correct |
2 ms |
5072 KB |
Output is correct |
32 |
Correct |
3 ms |
5072 KB |
Output is correct |
33 |
Correct |
3 ms |
5072 KB |
Output is correct |
34 |
Correct |
3 ms |
5072 KB |
Output is correct |
35 |
Correct |
2 ms |
5072 KB |
Output is correct |
36 |
Correct |
3 ms |
5072 KB |
Output is correct |
37 |
Correct |
3 ms |
5204 KB |
Output is correct |
38 |
Correct |
3 ms |
5200 KB |
Output is correct |
39 |
Correct |
3 ms |
5072 KB |
Output is correct |
40 |
Correct |
3 ms |
5072 KB |
Output is correct |
41 |
Correct |
3 ms |
5072 KB |
Output is correct |
42 |
Correct |
3 ms |
5072 KB |
Output is correct |
43 |
Correct |
576 ms |
8392 KB |
Output is correct |
44 |
Correct |
720 ms |
11648 KB |
Output is correct |
45 |
Correct |
782 ms |
11688 KB |
Output is correct |
46 |
Correct |
501 ms |
11660 KB |
Output is correct |
47 |
Correct |
673 ms |
8356 KB |
Output is correct |
48 |
Correct |
726 ms |
11680 KB |
Output is correct |
49 |
Correct |
704 ms |
11652 KB |
Output is correct |
50 |
Correct |
717 ms |
11664 KB |
Output is correct |
51 |
Correct |
347 ms |
5132 KB |
Output is correct |
52 |
Correct |
806 ms |
5392 KB |
Output is correct |
53 |
Correct |
713 ms |
5368 KB |
Output is correct |
54 |
Correct |
623 ms |
5372 KB |
Output is correct |
55 |
Correct |
723 ms |
15752 KB |
Output is correct |
56 |
Correct |
866 ms |
15772 KB |
Output is correct |
57 |
Correct |
734 ms |
15752 KB |
Output is correct |
58 |
Correct |
622 ms |
15792 KB |
Output is correct |
59 |
Correct |
892 ms |
22024 KB |
Output is correct |
60 |
Correct |
632 ms |
22088 KB |
Output is correct |
61 |
Correct |
420 ms |
5328 KB |
Output is correct |
62 |
Correct |
685 ms |
5328 KB |
Output is correct |
63 |
Correct |
626 ms |
5260 KB |
Output is correct |
64 |
Correct |
539 ms |
5516 KB |
Output is correct |
65 |
Correct |
709 ms |
5584 KB |
Output is correct |
66 |
Correct |
685 ms |
5576 KB |
Output is correct |
67 |
Correct |
597 ms |
5512 KB |
Output is correct |
68 |
Correct |
619 ms |
5584 KB |
Output is correct |
69 |
Correct |
771 ms |
5328 KB |
Output is correct |
70 |
Correct |
681 ms |
5260 KB |
Output is correct |
71 |
Correct |
541 ms |
5584 KB |
Output is correct |
72 |
Correct |
819 ms |
5520 KB |
Output is correct |
73 |
Correct |
585 ms |
5392 KB |
Output is correct |
74 |
Correct |
826 ms |
5372 KB |
Output is correct |
75 |
Correct |
665 ms |
5260 KB |
Output is correct |
76 |
Correct |
625 ms |
5768 KB |
Output is correct |
77 |
Correct |
770 ms |
5956 KB |
Output is correct |
78 |
Correct |
725 ms |
5956 KB |
Output is correct |
79 |
Correct |
722 ms |
5456 KB |
Output is correct |
80 |
Correct |
717 ms |
5260 KB |
Output is correct |
81 |
Correct |
682 ms |
5200 KB |
Output is correct |
82 |
Correct |
535 ms |
5328 KB |
Output is correct |
83 |
Correct |
331 ms |
5200 KB |
Output is correct |
84 |
Correct |
768 ms |
5388 KB |
Output is correct |
85 |
Correct |
647 ms |
5328 KB |
Output is correct |
86 |
Correct |
644 ms |
5328 KB |
Output is correct |
87 |
Correct |
2 ms |
4944 KB |
Output is correct |
88 |
Correct |
468 ms |
14976 KB |
Output is correct |
89 |
Correct |
718 ms |
11912 KB |
Output is correct |
90 |
Correct |
849 ms |
11612 KB |
Output is correct |
91 |
Correct |
834 ms |
15888 KB |
Output is correct |
92 |
Correct |
825 ms |
15944 KB |
Output is correct |
93 |
Correct |
818 ms |
15688 KB |
Output is correct |
94 |
Correct |
632 ms |
15912 KB |
Output is correct |
95 |
Correct |
823 ms |
15868 KB |
Output is correct |
96 |
Correct |
565 ms |
10852 KB |
Output is correct |
97 |
Correct |
775 ms |
10996 KB |
Output is correct |
98 |
Correct |
735 ms |
16636 KB |
Output is correct |
99 |
Correct |
787 ms |
15772 KB |
Output is correct |
100 |
Correct |
904 ms |
13064 KB |
Output is correct |
101 |
Correct |
832 ms |
12176 KB |
Output is correct |
102 |
Correct |
753 ms |
10876 KB |
Output is correct |
103 |
Correct |
622 ms |
22048 KB |
Output is correct |
104 |
Correct |
801 ms |
22564 KB |
Output is correct |
105 |
Correct |
887 ms |
22564 KB |
Output is correct |
106 |
Correct |
654 ms |
12940 KB |
Output is correct |
107 |
Correct |
949 ms |
11592 KB |
Output is correct |
108 |
Correct |
855 ms |
11420 KB |
Output is correct |
109 |
Correct |
766 ms |
10952 KB |
Output is correct |