#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[800800];
struct Seg1{
ll tree[800800], 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[800800];
int lazy[800800];
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];
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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
15232 KB |
Output is correct |
2 |
Correct |
6 ms |
15184 KB |
Output is correct |
3 |
Correct |
9 ms |
15184 KB |
Output is correct |
4 |
Correct |
9 ms |
15184 KB |
Output is correct |
5 |
Correct |
9 ms |
15220 KB |
Output is correct |
6 |
Correct |
7 ms |
15184 KB |
Output is correct |
7 |
Correct |
7 ms |
15156 KB |
Output is correct |
8 |
Correct |
9 ms |
15184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
15184 KB |
Output is correct |
2 |
Correct |
8 ms |
15184 KB |
Output is correct |
3 |
Correct |
7 ms |
15184 KB |
Output is correct |
4 |
Correct |
9 ms |
15184 KB |
Output is correct |
5 |
Correct |
8 ms |
15184 KB |
Output is correct |
6 |
Correct |
10 ms |
15188 KB |
Output is correct |
7 |
Correct |
9 ms |
15228 KB |
Output is correct |
8 |
Correct |
8 ms |
15184 KB |
Output is correct |
9 |
Correct |
7 ms |
15184 KB |
Output is correct |
10 |
Correct |
7 ms |
15312 KB |
Output is correct |
11 |
Correct |
8 ms |
15272 KB |
Output is correct |
12 |
Correct |
8 ms |
15160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
15232 KB |
Output is correct |
2 |
Correct |
6 ms |
15184 KB |
Output is correct |
3 |
Correct |
9 ms |
15184 KB |
Output is correct |
4 |
Correct |
9 ms |
15184 KB |
Output is correct |
5 |
Correct |
9 ms |
15220 KB |
Output is correct |
6 |
Correct |
7 ms |
15184 KB |
Output is correct |
7 |
Correct |
7 ms |
15156 KB |
Output is correct |
8 |
Correct |
9 ms |
15184 KB |
Output is correct |
9 |
Correct |
8 ms |
15184 KB |
Output is correct |
10 |
Correct |
8 ms |
15184 KB |
Output is correct |
11 |
Correct |
7 ms |
15184 KB |
Output is correct |
12 |
Correct |
9 ms |
15184 KB |
Output is correct |
13 |
Correct |
8 ms |
15184 KB |
Output is correct |
14 |
Correct |
10 ms |
15188 KB |
Output is correct |
15 |
Correct |
9 ms |
15228 KB |
Output is correct |
16 |
Correct |
8 ms |
15184 KB |
Output is correct |
17 |
Correct |
7 ms |
15184 KB |
Output is correct |
18 |
Correct |
7 ms |
15312 KB |
Output is correct |
19 |
Correct |
8 ms |
15272 KB |
Output is correct |
20 |
Correct |
8 ms |
15160 KB |
Output is correct |
21 |
Correct |
9 ms |
15184 KB |
Output is correct |
22 |
Correct |
7 ms |
15184 KB |
Output is correct |
23 |
Correct |
7 ms |
15184 KB |
Output is correct |
24 |
Correct |
9 ms |
15184 KB |
Output is correct |
25 |
Correct |
8 ms |
15184 KB |
Output is correct |
26 |
Correct |
8 ms |
15184 KB |
Output is correct |
27 |
Correct |
9 ms |
15184 KB |
Output is correct |
28 |
Correct |
8 ms |
15184 KB |
Output is correct |
29 |
Correct |
7 ms |
15184 KB |
Output is correct |
30 |
Correct |
7 ms |
15184 KB |
Output is correct |
31 |
Correct |
9 ms |
15184 KB |
Output is correct |
32 |
Correct |
7 ms |
15236 KB |
Output is correct |
33 |
Correct |
7 ms |
15184 KB |
Output is correct |
34 |
Correct |
7 ms |
15184 KB |
Output is correct |
35 |
Correct |
8 ms |
15184 KB |
Output is correct |
36 |
Correct |
9 ms |
15256 KB |
Output is correct |
37 |
Correct |
7 ms |
15312 KB |
Output is correct |
38 |
Correct |
11 ms |
15312 KB |
Output is correct |
39 |
Correct |
7 ms |
15184 KB |
Output is correct |
40 |
Correct |
9 ms |
15204 KB |
Output is correct |
41 |
Correct |
8 ms |
15184 KB |
Output is correct |
42 |
Correct |
9 ms |
15184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
722 ms |
17884 KB |
Output is correct |
2 |
Runtime error |
57 ms |
40264 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
722 ms |
17884 KB |
Output is correct |
2 |
Runtime error |
57 ms |
40264 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
15184 KB |
Output is correct |
2 |
Correct |
8 ms |
15184 KB |
Output is correct |
3 |
Correct |
7 ms |
15184 KB |
Output is correct |
4 |
Correct |
9 ms |
15184 KB |
Output is correct |
5 |
Correct |
8 ms |
15184 KB |
Output is correct |
6 |
Correct |
10 ms |
15188 KB |
Output is correct |
7 |
Correct |
9 ms |
15228 KB |
Output is correct |
8 |
Correct |
8 ms |
15184 KB |
Output is correct |
9 |
Correct |
7 ms |
15184 KB |
Output is correct |
10 |
Correct |
7 ms |
15312 KB |
Output is correct |
11 |
Correct |
8 ms |
15272 KB |
Output is correct |
12 |
Correct |
8 ms |
15160 KB |
Output is correct |
13 |
Correct |
722 ms |
17884 KB |
Output is correct |
14 |
Runtime error |
57 ms |
40264 KB |
Execution killed with signal 11 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
15232 KB |
Output is correct |
2 |
Correct |
6 ms |
15184 KB |
Output is correct |
3 |
Correct |
9 ms |
15184 KB |
Output is correct |
4 |
Correct |
9 ms |
15184 KB |
Output is correct |
5 |
Correct |
9 ms |
15220 KB |
Output is correct |
6 |
Correct |
7 ms |
15184 KB |
Output is correct |
7 |
Correct |
7 ms |
15156 KB |
Output is correct |
8 |
Correct |
9 ms |
15184 KB |
Output is correct |
9 |
Correct |
8 ms |
15184 KB |
Output is correct |
10 |
Correct |
8 ms |
15184 KB |
Output is correct |
11 |
Correct |
7 ms |
15184 KB |
Output is correct |
12 |
Correct |
9 ms |
15184 KB |
Output is correct |
13 |
Correct |
8 ms |
15184 KB |
Output is correct |
14 |
Correct |
10 ms |
15188 KB |
Output is correct |
15 |
Correct |
9 ms |
15228 KB |
Output is correct |
16 |
Correct |
8 ms |
15184 KB |
Output is correct |
17 |
Correct |
7 ms |
15184 KB |
Output is correct |
18 |
Correct |
7 ms |
15312 KB |
Output is correct |
19 |
Correct |
8 ms |
15272 KB |
Output is correct |
20 |
Correct |
8 ms |
15160 KB |
Output is correct |
21 |
Correct |
9 ms |
15184 KB |
Output is correct |
22 |
Correct |
7 ms |
15184 KB |
Output is correct |
23 |
Correct |
7 ms |
15184 KB |
Output is correct |
24 |
Correct |
9 ms |
15184 KB |
Output is correct |
25 |
Correct |
8 ms |
15184 KB |
Output is correct |
26 |
Correct |
8 ms |
15184 KB |
Output is correct |
27 |
Correct |
9 ms |
15184 KB |
Output is correct |
28 |
Correct |
8 ms |
15184 KB |
Output is correct |
29 |
Correct |
7 ms |
15184 KB |
Output is correct |
30 |
Correct |
7 ms |
15184 KB |
Output is correct |
31 |
Correct |
9 ms |
15184 KB |
Output is correct |
32 |
Correct |
7 ms |
15236 KB |
Output is correct |
33 |
Correct |
7 ms |
15184 KB |
Output is correct |
34 |
Correct |
7 ms |
15184 KB |
Output is correct |
35 |
Correct |
8 ms |
15184 KB |
Output is correct |
36 |
Correct |
9 ms |
15256 KB |
Output is correct |
37 |
Correct |
7 ms |
15312 KB |
Output is correct |
38 |
Correct |
11 ms |
15312 KB |
Output is correct |
39 |
Correct |
7 ms |
15184 KB |
Output is correct |
40 |
Correct |
9 ms |
15204 KB |
Output is correct |
41 |
Correct |
8 ms |
15184 KB |
Output is correct |
42 |
Correct |
9 ms |
15184 KB |
Output is correct |
43 |
Correct |
684 ms |
15440 KB |
Output is correct |
44 |
Correct |
1295 ms |
15440 KB |
Output is correct |
45 |
Correct |
999 ms |
15488 KB |
Output is correct |
46 |
Correct |
578 ms |
15568 KB |
Output is correct |
47 |
Correct |
818 ms |
15636 KB |
Output is correct |
48 |
Correct |
690 ms |
15616 KB |
Output is correct |
49 |
Correct |
1061 ms |
15568 KB |
Output is correct |
50 |
Correct |
1118 ms |
15632 KB |
Output is correct |
51 |
Correct |
951 ms |
15312 KB |
Output is correct |
52 |
Correct |
1030 ms |
15312 KB |
Output is correct |
53 |
Correct |
773 ms |
15696 KB |
Output is correct |
54 |
Correct |
913 ms |
15640 KB |
Output is correct |
55 |
Correct |
886 ms |
15440 KB |
Output is correct |
56 |
Correct |
908 ms |
15440 KB |
Output is correct |
57 |
Correct |
909 ms |
15272 KB |
Output is correct |
58 |
Correct |
942 ms |
15872 KB |
Output is correct |
59 |
Correct |
1118 ms |
15912 KB |
Output is correct |
60 |
Correct |
699 ms |
15920 KB |
Output is correct |
61 |
Correct |
1081 ms |
15480 KB |
Output is correct |
62 |
Correct |
919 ms |
15412 KB |
Output is correct |
63 |
Correct |
1094 ms |
15312 KB |
Output is correct |
64 |
Correct |
940 ms |
15312 KB |
Output is correct |
65 |
Correct |
558 ms |
15344 KB |
Output is correct |
66 |
Correct |
1108 ms |
15464 KB |
Output is correct |
67 |
Correct |
1109 ms |
15440 KB |
Output is correct |
68 |
Correct |
966 ms |
15488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
15232 KB |
Output is correct |
2 |
Correct |
6 ms |
15184 KB |
Output is correct |
3 |
Correct |
9 ms |
15184 KB |
Output is correct |
4 |
Correct |
9 ms |
15184 KB |
Output is correct |
5 |
Correct |
9 ms |
15220 KB |
Output is correct |
6 |
Correct |
7 ms |
15184 KB |
Output is correct |
7 |
Correct |
7 ms |
15156 KB |
Output is correct |
8 |
Correct |
9 ms |
15184 KB |
Output is correct |
9 |
Correct |
8 ms |
15184 KB |
Output is correct |
10 |
Correct |
8 ms |
15184 KB |
Output is correct |
11 |
Correct |
7 ms |
15184 KB |
Output is correct |
12 |
Correct |
9 ms |
15184 KB |
Output is correct |
13 |
Correct |
8 ms |
15184 KB |
Output is correct |
14 |
Correct |
10 ms |
15188 KB |
Output is correct |
15 |
Correct |
9 ms |
15228 KB |
Output is correct |
16 |
Correct |
8 ms |
15184 KB |
Output is correct |
17 |
Correct |
7 ms |
15184 KB |
Output is correct |
18 |
Correct |
7 ms |
15312 KB |
Output is correct |
19 |
Correct |
8 ms |
15272 KB |
Output is correct |
20 |
Correct |
8 ms |
15160 KB |
Output is correct |
21 |
Correct |
9 ms |
15184 KB |
Output is correct |
22 |
Correct |
7 ms |
15184 KB |
Output is correct |
23 |
Correct |
7 ms |
15184 KB |
Output is correct |
24 |
Correct |
9 ms |
15184 KB |
Output is correct |
25 |
Correct |
8 ms |
15184 KB |
Output is correct |
26 |
Correct |
8 ms |
15184 KB |
Output is correct |
27 |
Correct |
9 ms |
15184 KB |
Output is correct |
28 |
Correct |
8 ms |
15184 KB |
Output is correct |
29 |
Correct |
7 ms |
15184 KB |
Output is correct |
30 |
Correct |
7 ms |
15184 KB |
Output is correct |
31 |
Correct |
9 ms |
15184 KB |
Output is correct |
32 |
Correct |
7 ms |
15236 KB |
Output is correct |
33 |
Correct |
7 ms |
15184 KB |
Output is correct |
34 |
Correct |
7 ms |
15184 KB |
Output is correct |
35 |
Correct |
8 ms |
15184 KB |
Output is correct |
36 |
Correct |
9 ms |
15256 KB |
Output is correct |
37 |
Correct |
7 ms |
15312 KB |
Output is correct |
38 |
Correct |
11 ms |
15312 KB |
Output is correct |
39 |
Correct |
7 ms |
15184 KB |
Output is correct |
40 |
Correct |
9 ms |
15204 KB |
Output is correct |
41 |
Correct |
8 ms |
15184 KB |
Output is correct |
42 |
Correct |
9 ms |
15184 KB |
Output is correct |
43 |
Correct |
722 ms |
17884 KB |
Output is correct |
44 |
Runtime error |
57 ms |
40264 KB |
Execution killed with signal 11 |
45 |
Halted |
0 ms |
0 KB |
- |