#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1'000'002'022;
vector<int> adj[100100];
int n, m, a[100100];
struct Seg1{
ll tree[200200], sz;
void init(int n){
sz = n;
for (int i=sz;i<sz*2;i++) tree[i] = adj[i-sz].size();
for (int i=sz-1;i;i--) tree[i] = tree[i<<1] * tree[i<<1|1] % MOD;
}
void update(int p, int x){
for (tree[p+=sz]=x;p>1;p>>=1) tree[p>>1] = tree[p] * tree[p^1] % MOD;
}
}tree1;
struct Seg2{
pair<ll, ll> tree[400400];
int lazy[400400];
pair<ll, ll> combine(pair<ll, ll> x, pair<ll, ll> y){return {(x.first + y.first)%MOD, (x.second + y.second)%MOD};}
void init(int i, int l, int r){
lazy[i] = 0;
if (l==r) {tree[i] = {0, a[l]}; return;}
int m = (l+r)>>1;
init(i<<1, l, m); init(i<<1|1, m+1, r);
tree[i] = combine(tree[i<<1], tree[i<<1|1]);
}
void propagate(int i, int l, int r){
if (!lazy[i]) return;
swap(tree[i].first, tree[i].second);
if (l!=r){
lazy[i<<1] ^= 1;
lazy[i<<1|1] ^= 1;
}
lazy[i] = 0;
}
void update(int i, int l, int r, int s, int e){
propagate(i, l, r);
if (r<s || e<l) return;
if (s<=l && r<=e){
lazy[i] ^= 1;
propagate(i, l, r);
return;
}
int m = (l+r)>>1;
update(i<<1, l, m, s, e); update(i<<1|1, m+1, r, s, e);
tree[i] = combine(tree[i<<1], tree[i<<1|1]);
}
}tree2;
void dfs(int s){
if (s<=n) tree1.update(s, 1);
else {a[s-n] = tree1.tree[1]; return;}
for (auto &v:adj[s]) dfs(v);
if (s<=n) tree1.update(s, adj[s].size());
}
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
adj[0].push_back(0);
n = N, m = M;
for (int i=1;i<n+m;i++){
adj[P[i]+1].push_back(i+1);
}
tree1.init(n+1);
dfs(1);
tree2.init(1, 1, m);
for (int i=0;i<m;i++) if (A[i]) tree2.update(1, 1, m, i+1, i+1);
}
int count_ways(int L, int R) {
tree2.update(1, 1, m, L-n+1, R-n+1);
return tree2.tree[1].first;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8960 KB |
Output is correct |
2 |
Correct |
6 ms |
8956 KB |
Output is correct |
3 |
Correct |
5 ms |
8912 KB |
Output is correct |
4 |
Correct |
5 ms |
8912 KB |
Output is correct |
5 |
Correct |
6 ms |
8912 KB |
Output is correct |
6 |
Correct |
6 ms |
8912 KB |
Output is correct |
7 |
Correct |
6 ms |
8912 KB |
Output is correct |
8 |
Correct |
5 ms |
8944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8912 KB |
Output is correct |
2 |
Correct |
5 ms |
8956 KB |
Output is correct |
3 |
Correct |
6 ms |
8960 KB |
Output is correct |
4 |
Correct |
7 ms |
8960 KB |
Output is correct |
5 |
Correct |
7 ms |
8912 KB |
Output is correct |
6 |
Correct |
6 ms |
8912 KB |
Output is correct |
7 |
Correct |
6 ms |
8912 KB |
Output is correct |
8 |
Correct |
6 ms |
8968 KB |
Output is correct |
9 |
Correct |
5 ms |
8912 KB |
Output is correct |
10 |
Correct |
6 ms |
9040 KB |
Output is correct |
11 |
Correct |
6 ms |
9040 KB |
Output is correct |
12 |
Correct |
5 ms |
8948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8960 KB |
Output is correct |
2 |
Correct |
6 ms |
8956 KB |
Output is correct |
3 |
Correct |
5 ms |
8912 KB |
Output is correct |
4 |
Correct |
5 ms |
8912 KB |
Output is correct |
5 |
Correct |
6 ms |
8912 KB |
Output is correct |
6 |
Correct |
6 ms |
8912 KB |
Output is correct |
7 |
Correct |
6 ms |
8912 KB |
Output is correct |
8 |
Correct |
5 ms |
8944 KB |
Output is correct |
9 |
Correct |
4 ms |
8912 KB |
Output is correct |
10 |
Correct |
5 ms |
8956 KB |
Output is correct |
11 |
Correct |
6 ms |
8960 KB |
Output is correct |
12 |
Correct |
7 ms |
8960 KB |
Output is correct |
13 |
Correct |
7 ms |
8912 KB |
Output is correct |
14 |
Correct |
6 ms |
8912 KB |
Output is correct |
15 |
Correct |
6 ms |
8912 KB |
Output is correct |
16 |
Correct |
6 ms |
8968 KB |
Output is correct |
17 |
Correct |
5 ms |
8912 KB |
Output is correct |
18 |
Correct |
6 ms |
9040 KB |
Output is correct |
19 |
Correct |
6 ms |
9040 KB |
Output is correct |
20 |
Correct |
5 ms |
8948 KB |
Output is correct |
21 |
Correct |
6 ms |
8948 KB |
Output is correct |
22 |
Correct |
5 ms |
8912 KB |
Output is correct |
23 |
Correct |
5 ms |
8912 KB |
Output is correct |
24 |
Correct |
5 ms |
8912 KB |
Output is correct |
25 |
Correct |
5 ms |
9016 KB |
Output is correct |
26 |
Correct |
6 ms |
8912 KB |
Output is correct |
27 |
Correct |
7 ms |
8992 KB |
Output is correct |
28 |
Correct |
7 ms |
9012 KB |
Output is correct |
29 |
Correct |
5 ms |
8960 KB |
Output is correct |
30 |
Correct |
6 ms |
8912 KB |
Output is correct |
31 |
Correct |
6 ms |
9040 KB |
Output is correct |
32 |
Correct |
5 ms |
8936 KB |
Output is correct |
33 |
Correct |
5 ms |
8912 KB |
Output is correct |
34 |
Correct |
6 ms |
8888 KB |
Output is correct |
35 |
Correct |
5 ms |
8912 KB |
Output is correct |
36 |
Correct |
5 ms |
9088 KB |
Output is correct |
37 |
Correct |
5 ms |
9040 KB |
Output is correct |
38 |
Correct |
5 ms |
9088 KB |
Output is correct |
39 |
Correct |
5 ms |
8912 KB |
Output is correct |
40 |
Correct |
5 ms |
8912 KB |
Output is correct |
41 |
Correct |
5 ms |
8912 KB |
Output is correct |
42 |
Correct |
5 ms |
8940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
985 ms |
11604 KB |
Output is correct |
2 |
Correct |
935 ms |
14272 KB |
Output is correct |
3 |
Correct |
1062 ms |
14292 KB |
Output is correct |
4 |
Correct |
868 ms |
14292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
985 ms |
11604 KB |
Output is correct |
2 |
Correct |
935 ms |
14272 KB |
Output is correct |
3 |
Correct |
1062 ms |
14292 KB |
Output is correct |
4 |
Correct |
868 ms |
14292 KB |
Output is correct |
5 |
Correct |
1018 ms |
11676 KB |
Output is correct |
6 |
Correct |
1084 ms |
14276 KB |
Output is correct |
7 |
Correct |
1177 ms |
14296 KB |
Output is correct |
8 |
Correct |
936 ms |
14356 KB |
Output is correct |
9 |
Correct |
479 ms |
9088 KB |
Output is correct |
10 |
Correct |
1041 ms |
9168 KB |
Output is correct |
11 |
Correct |
837 ms |
9168 KB |
Output is correct |
12 |
Correct |
908 ms |
9168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8912 KB |
Output is correct |
2 |
Correct |
5 ms |
8956 KB |
Output is correct |
3 |
Correct |
6 ms |
8960 KB |
Output is correct |
4 |
Correct |
7 ms |
8960 KB |
Output is correct |
5 |
Correct |
7 ms |
8912 KB |
Output is correct |
6 |
Correct |
6 ms |
8912 KB |
Output is correct |
7 |
Correct |
6 ms |
8912 KB |
Output is correct |
8 |
Correct |
6 ms |
8968 KB |
Output is correct |
9 |
Correct |
5 ms |
8912 KB |
Output is correct |
10 |
Correct |
6 ms |
9040 KB |
Output is correct |
11 |
Correct |
6 ms |
9040 KB |
Output is correct |
12 |
Correct |
5 ms |
8948 KB |
Output is correct |
13 |
Correct |
985 ms |
11604 KB |
Output is correct |
14 |
Correct |
935 ms |
14272 KB |
Output is correct |
15 |
Correct |
1062 ms |
14292 KB |
Output is correct |
16 |
Correct |
868 ms |
14292 KB |
Output is correct |
17 |
Correct |
1018 ms |
11676 KB |
Output is correct |
18 |
Correct |
1084 ms |
14276 KB |
Output is correct |
19 |
Correct |
1177 ms |
14296 KB |
Output is correct |
20 |
Correct |
936 ms |
14356 KB |
Output is correct |
21 |
Correct |
479 ms |
9088 KB |
Output is correct |
22 |
Correct |
1041 ms |
9168 KB |
Output is correct |
23 |
Correct |
837 ms |
9168 KB |
Output is correct |
24 |
Correct |
908 ms |
9168 KB |
Output is correct |
25 |
Correct |
866 ms |
17248 KB |
Output is correct |
26 |
Correct |
1004 ms |
17380 KB |
Output is correct |
27 |
Correct |
1080 ms |
17364 KB |
Output is correct |
28 |
Correct |
829 ms |
17380 KB |
Output is correct |
29 |
Correct |
1067 ms |
23524 KB |
Output is correct |
30 |
Correct |
748 ms |
23636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8960 KB |
Output is correct |
2 |
Correct |
6 ms |
8956 KB |
Output is correct |
3 |
Correct |
5 ms |
8912 KB |
Output is correct |
4 |
Correct |
5 ms |
8912 KB |
Output is correct |
5 |
Correct |
6 ms |
8912 KB |
Output is correct |
6 |
Correct |
6 ms |
8912 KB |
Output is correct |
7 |
Correct |
6 ms |
8912 KB |
Output is correct |
8 |
Correct |
5 ms |
8944 KB |
Output is correct |
9 |
Correct |
4 ms |
8912 KB |
Output is correct |
10 |
Correct |
5 ms |
8956 KB |
Output is correct |
11 |
Correct |
6 ms |
8960 KB |
Output is correct |
12 |
Correct |
7 ms |
8960 KB |
Output is correct |
13 |
Correct |
7 ms |
8912 KB |
Output is correct |
14 |
Correct |
6 ms |
8912 KB |
Output is correct |
15 |
Correct |
6 ms |
8912 KB |
Output is correct |
16 |
Correct |
6 ms |
8968 KB |
Output is correct |
17 |
Correct |
5 ms |
8912 KB |
Output is correct |
18 |
Correct |
6 ms |
9040 KB |
Output is correct |
19 |
Correct |
6 ms |
9040 KB |
Output is correct |
20 |
Correct |
5 ms |
8948 KB |
Output is correct |
21 |
Correct |
6 ms |
8948 KB |
Output is correct |
22 |
Correct |
5 ms |
8912 KB |
Output is correct |
23 |
Correct |
5 ms |
8912 KB |
Output is correct |
24 |
Correct |
5 ms |
8912 KB |
Output is correct |
25 |
Correct |
5 ms |
9016 KB |
Output is correct |
26 |
Correct |
6 ms |
8912 KB |
Output is correct |
27 |
Correct |
7 ms |
8992 KB |
Output is correct |
28 |
Correct |
7 ms |
9012 KB |
Output is correct |
29 |
Correct |
5 ms |
8960 KB |
Output is correct |
30 |
Correct |
6 ms |
8912 KB |
Output is correct |
31 |
Correct |
6 ms |
9040 KB |
Output is correct |
32 |
Correct |
5 ms |
8936 KB |
Output is correct |
33 |
Correct |
5 ms |
8912 KB |
Output is correct |
34 |
Correct |
6 ms |
8888 KB |
Output is correct |
35 |
Correct |
5 ms |
8912 KB |
Output is correct |
36 |
Correct |
5 ms |
9088 KB |
Output is correct |
37 |
Correct |
5 ms |
9040 KB |
Output is correct |
38 |
Correct |
5 ms |
9088 KB |
Output is correct |
39 |
Correct |
5 ms |
8912 KB |
Output is correct |
40 |
Correct |
5 ms |
8912 KB |
Output is correct |
41 |
Correct |
5 ms |
8912 KB |
Output is correct |
42 |
Correct |
5 ms |
8940 KB |
Output is correct |
43 |
Correct |
556 ms |
9168 KB |
Output is correct |
44 |
Correct |
879 ms |
9208 KB |
Output is correct |
45 |
Correct |
836 ms |
9168 KB |
Output is correct |
46 |
Correct |
899 ms |
9296 KB |
Output is correct |
47 |
Correct |
851 ms |
9296 KB |
Output is correct |
48 |
Correct |
752 ms |
9296 KB |
Output is correct |
49 |
Correct |
658 ms |
9296 KB |
Output is correct |
50 |
Correct |
704 ms |
9296 KB |
Output is correct |
51 |
Correct |
743 ms |
9040 KB |
Output is correct |
52 |
Correct |
922 ms |
9040 KB |
Output is correct |
53 |
Correct |
732 ms |
9424 KB |
Output is correct |
54 |
Correct |
654 ms |
9296 KB |
Output is correct |
55 |
Correct |
766 ms |
9168 KB |
Output is correct |
56 |
Correct |
917 ms |
9168 KB |
Output is correct |
57 |
Correct |
790 ms |
9040 KB |
Output is correct |
58 |
Correct |
741 ms |
9552 KB |
Output is correct |
59 |
Correct |
784 ms |
9724 KB |
Output is correct |
60 |
Correct |
735 ms |
9712 KB |
Output is correct |
61 |
Correct |
788 ms |
9296 KB |
Output is correct |
62 |
Correct |
785 ms |
9040 KB |
Output is correct |
63 |
Correct |
715 ms |
9040 KB |
Output is correct |
64 |
Correct |
807 ms |
9040 KB |
Output is correct |
65 |
Correct |
484 ms |
9040 KB |
Output is correct |
66 |
Correct |
785 ms |
9228 KB |
Output is correct |
67 |
Correct |
868 ms |
9168 KB |
Output is correct |
68 |
Correct |
1067 ms |
9168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8960 KB |
Output is correct |
2 |
Correct |
6 ms |
8956 KB |
Output is correct |
3 |
Correct |
5 ms |
8912 KB |
Output is correct |
4 |
Correct |
5 ms |
8912 KB |
Output is correct |
5 |
Correct |
6 ms |
8912 KB |
Output is correct |
6 |
Correct |
6 ms |
8912 KB |
Output is correct |
7 |
Correct |
6 ms |
8912 KB |
Output is correct |
8 |
Correct |
5 ms |
8944 KB |
Output is correct |
9 |
Correct |
4 ms |
8912 KB |
Output is correct |
10 |
Correct |
5 ms |
8956 KB |
Output is correct |
11 |
Correct |
6 ms |
8960 KB |
Output is correct |
12 |
Correct |
7 ms |
8960 KB |
Output is correct |
13 |
Correct |
7 ms |
8912 KB |
Output is correct |
14 |
Correct |
6 ms |
8912 KB |
Output is correct |
15 |
Correct |
6 ms |
8912 KB |
Output is correct |
16 |
Correct |
6 ms |
8968 KB |
Output is correct |
17 |
Correct |
5 ms |
8912 KB |
Output is correct |
18 |
Correct |
6 ms |
9040 KB |
Output is correct |
19 |
Correct |
6 ms |
9040 KB |
Output is correct |
20 |
Correct |
5 ms |
8948 KB |
Output is correct |
21 |
Correct |
6 ms |
8948 KB |
Output is correct |
22 |
Correct |
5 ms |
8912 KB |
Output is correct |
23 |
Correct |
5 ms |
8912 KB |
Output is correct |
24 |
Correct |
5 ms |
8912 KB |
Output is correct |
25 |
Correct |
5 ms |
9016 KB |
Output is correct |
26 |
Correct |
6 ms |
8912 KB |
Output is correct |
27 |
Correct |
7 ms |
8992 KB |
Output is correct |
28 |
Correct |
7 ms |
9012 KB |
Output is correct |
29 |
Correct |
5 ms |
8960 KB |
Output is correct |
30 |
Correct |
6 ms |
8912 KB |
Output is correct |
31 |
Correct |
6 ms |
9040 KB |
Output is correct |
32 |
Correct |
5 ms |
8936 KB |
Output is correct |
33 |
Correct |
5 ms |
8912 KB |
Output is correct |
34 |
Correct |
6 ms |
8888 KB |
Output is correct |
35 |
Correct |
5 ms |
8912 KB |
Output is correct |
36 |
Correct |
5 ms |
9088 KB |
Output is correct |
37 |
Correct |
5 ms |
9040 KB |
Output is correct |
38 |
Correct |
5 ms |
9088 KB |
Output is correct |
39 |
Correct |
5 ms |
8912 KB |
Output is correct |
40 |
Correct |
5 ms |
8912 KB |
Output is correct |
41 |
Correct |
5 ms |
8912 KB |
Output is correct |
42 |
Correct |
5 ms |
8940 KB |
Output is correct |
43 |
Correct |
985 ms |
11604 KB |
Output is correct |
44 |
Correct |
935 ms |
14272 KB |
Output is correct |
45 |
Correct |
1062 ms |
14292 KB |
Output is correct |
46 |
Correct |
868 ms |
14292 KB |
Output is correct |
47 |
Correct |
1018 ms |
11676 KB |
Output is correct |
48 |
Correct |
1084 ms |
14276 KB |
Output is correct |
49 |
Correct |
1177 ms |
14296 KB |
Output is correct |
50 |
Correct |
936 ms |
14356 KB |
Output is correct |
51 |
Correct |
479 ms |
9088 KB |
Output is correct |
52 |
Correct |
1041 ms |
9168 KB |
Output is correct |
53 |
Correct |
837 ms |
9168 KB |
Output is correct |
54 |
Correct |
908 ms |
9168 KB |
Output is correct |
55 |
Correct |
866 ms |
17248 KB |
Output is correct |
56 |
Correct |
1004 ms |
17380 KB |
Output is correct |
57 |
Correct |
1080 ms |
17364 KB |
Output is correct |
58 |
Correct |
829 ms |
17380 KB |
Output is correct |
59 |
Correct |
1067 ms |
23524 KB |
Output is correct |
60 |
Correct |
748 ms |
23636 KB |
Output is correct |
61 |
Correct |
556 ms |
9168 KB |
Output is correct |
62 |
Correct |
879 ms |
9208 KB |
Output is correct |
63 |
Correct |
836 ms |
9168 KB |
Output is correct |
64 |
Correct |
899 ms |
9296 KB |
Output is correct |
65 |
Correct |
851 ms |
9296 KB |
Output is correct |
66 |
Correct |
752 ms |
9296 KB |
Output is correct |
67 |
Correct |
658 ms |
9296 KB |
Output is correct |
68 |
Correct |
704 ms |
9296 KB |
Output is correct |
69 |
Correct |
743 ms |
9040 KB |
Output is correct |
70 |
Correct |
922 ms |
9040 KB |
Output is correct |
71 |
Correct |
732 ms |
9424 KB |
Output is correct |
72 |
Correct |
654 ms |
9296 KB |
Output is correct |
73 |
Correct |
766 ms |
9168 KB |
Output is correct |
74 |
Correct |
917 ms |
9168 KB |
Output is correct |
75 |
Correct |
790 ms |
9040 KB |
Output is correct |
76 |
Correct |
741 ms |
9552 KB |
Output is correct |
77 |
Correct |
784 ms |
9724 KB |
Output is correct |
78 |
Correct |
735 ms |
9712 KB |
Output is correct |
79 |
Correct |
788 ms |
9296 KB |
Output is correct |
80 |
Correct |
785 ms |
9040 KB |
Output is correct |
81 |
Correct |
715 ms |
9040 KB |
Output is correct |
82 |
Correct |
807 ms |
9040 KB |
Output is correct |
83 |
Correct |
484 ms |
9040 KB |
Output is correct |
84 |
Correct |
785 ms |
9228 KB |
Output is correct |
85 |
Correct |
868 ms |
9168 KB |
Output is correct |
86 |
Correct |
1067 ms |
9168 KB |
Output is correct |
87 |
Correct |
4 ms |
8924 KB |
Output is correct |
88 |
Correct |
630 ms |
16656 KB |
Output is correct |
89 |
Correct |
1125 ms |
14604 KB |
Output is correct |
90 |
Correct |
977 ms |
14228 KB |
Output is correct |
91 |
Correct |
1094 ms |
17476 KB |
Output is correct |
92 |
Correct |
988 ms |
17508 KB |
Output is correct |
93 |
Correct |
904 ms |
17384 KB |
Output is correct |
94 |
Correct |
1084 ms |
17500 KB |
Output is correct |
95 |
Correct |
840 ms |
17388 KB |
Output is correct |
96 |
Correct |
776 ms |
12360 KB |
Output is correct |
97 |
Correct |
843 ms |
12352 KB |
Output is correct |
98 |
Correct |
485 ms |
20560 KB |
Output is correct |
99 |
Correct |
1004 ms |
17352 KB |
Output is correct |
100 |
Correct |
785 ms |
14596 KB |
Output is correct |
101 |
Correct |
887 ms |
13908 KB |
Output is correct |
102 |
Correct |
851 ms |
12396 KB |
Output is correct |
103 |
Correct |
918 ms |
23628 KB |
Output is correct |
104 |
Correct |
853 ms |
24044 KB |
Output is correct |
105 |
Correct |
829 ms |
24044 KB |
Output is correct |
106 |
Correct |
957 ms |
15816 KB |
Output is correct |
107 |
Correct |
1006 ms |
13508 KB |
Output is correct |
108 |
Correct |
966 ms |
13256 KB |
Output is correct |
109 |
Correct |
731 ms |
12496 KB |
Output is correct |