#include "circuit.h"
#include<bits/stdc++.h>
using namespace std;
#define int long long int
vector<int> adj[200005];
int p[200005], vis[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 dfs(int i) {
vis[i] = 1;
if (i != 0) {
dfs(p[i]);
}
}
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++) {
p[i] = P[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;
}
dfs(0);
for (int i = 0; i < m; i++) {
int v = 1;
for (int j = 0; j < n; j++) {
vis[j] = 0;
}
dfs(n+i);
for (int j = 0; j < n; j++) {
if (vis[j]) {
continue;
}
v *= adj[j].size();
v %= mod;
}
if (A[i]) {
arr[i] = v;
} else {
brr[i] = v;
}
}
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 |
2 ms |
4952 KB |
Output is correct |
3 |
Correct |
2 ms |
5208 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 |
2 ms |
5208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4952 KB |
Output is correct |
2 |
Correct |
4 ms |
5208 KB |
Output is correct |
3 |
Correct |
3 ms |
5208 KB |
Output is correct |
4 |
Correct |
4 ms |
5208 KB |
Output is correct |
5 |
Correct |
3 ms |
5208 KB |
Output is correct |
6 |
Correct |
6 ms |
5208 KB |
Output is correct |
7 |
Correct |
7 ms |
5208 KB |
Output is correct |
8 |
Correct |
7 ms |
5268 KB |
Output is correct |
9 |
Correct |
7 ms |
5260 KB |
Output is correct |
10 |
Correct |
6 ms |
5208 KB |
Output is correct |
11 |
Correct |
6 ms |
5264 KB |
Output is correct |
12 |
Correct |
6 ms |
5208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4952 KB |
Output is correct |
3 |
Correct |
2 ms |
5208 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 |
2 ms |
5208 KB |
Output is correct |
9 |
Correct |
3 ms |
4952 KB |
Output is correct |
10 |
Correct |
4 ms |
5208 KB |
Output is correct |
11 |
Correct |
3 ms |
5208 KB |
Output is correct |
12 |
Correct |
4 ms |
5208 KB |
Output is correct |
13 |
Correct |
3 ms |
5208 KB |
Output is correct |
14 |
Correct |
6 ms |
5208 KB |
Output is correct |
15 |
Correct |
7 ms |
5208 KB |
Output is correct |
16 |
Correct |
7 ms |
5268 KB |
Output is correct |
17 |
Correct |
7 ms |
5260 KB |
Output is correct |
18 |
Correct |
6 ms |
5208 KB |
Output is correct |
19 |
Correct |
6 ms |
5264 KB |
Output is correct |
20 |
Correct |
6 ms |
5208 KB |
Output is correct |
21 |
Correct |
6 ms |
5208 KB |
Output is correct |
22 |
Correct |
4 ms |
5208 KB |
Output is correct |
23 |
Correct |
4 ms |
5208 KB |
Output is correct |
24 |
Correct |
7 ms |
5260 KB |
Output is correct |
25 |
Correct |
7 ms |
5208 KB |
Output is correct |
26 |
Correct |
7 ms |
5204 KB |
Output is correct |
27 |
Correct |
7 ms |
5208 KB |
Output is correct |
28 |
Correct |
7 ms |
5272 KB |
Output is correct |
29 |
Correct |
3 ms |
5236 KB |
Output is correct |
30 |
Correct |
3 ms |
5208 KB |
Output is correct |
31 |
Correct |
2 ms |
5208 KB |
Output is correct |
32 |
Correct |
7 ms |
5208 KB |
Output is correct |
33 |
Correct |
5 ms |
5208 KB |
Output is correct |
34 |
Correct |
3 ms |
5208 KB |
Output is correct |
35 |
Correct |
2 ms |
5208 KB |
Output is correct |
36 |
Correct |
6 ms |
5208 KB |
Output is correct |
37 |
Correct |
5 ms |
5284 KB |
Output is correct |
38 |
Correct |
5 ms |
5208 KB |
Output is correct |
39 |
Correct |
4 ms |
5208 KB |
Output is correct |
40 |
Correct |
4 ms |
5208 KB |
Output is correct |
41 |
Correct |
4 ms |
5208 KB |
Output is correct |
42 |
Correct |
2 ms |
5208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3063 ms |
8252 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3063 ms |
8252 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4952 KB |
Output is correct |
2 |
Correct |
4 ms |
5208 KB |
Output is correct |
3 |
Correct |
3 ms |
5208 KB |
Output is correct |
4 |
Correct |
4 ms |
5208 KB |
Output is correct |
5 |
Correct |
3 ms |
5208 KB |
Output is correct |
6 |
Correct |
6 ms |
5208 KB |
Output is correct |
7 |
Correct |
7 ms |
5208 KB |
Output is correct |
8 |
Correct |
7 ms |
5268 KB |
Output is correct |
9 |
Correct |
7 ms |
5260 KB |
Output is correct |
10 |
Correct |
6 ms |
5208 KB |
Output is correct |
11 |
Correct |
6 ms |
5264 KB |
Output is correct |
12 |
Correct |
6 ms |
5208 KB |
Output is correct |
13 |
Execution timed out |
3063 ms |
8252 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4952 KB |
Output is correct |
3 |
Correct |
2 ms |
5208 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 |
2 ms |
5208 KB |
Output is correct |
9 |
Correct |
3 ms |
4952 KB |
Output is correct |
10 |
Correct |
4 ms |
5208 KB |
Output is correct |
11 |
Correct |
3 ms |
5208 KB |
Output is correct |
12 |
Correct |
4 ms |
5208 KB |
Output is correct |
13 |
Correct |
3 ms |
5208 KB |
Output is correct |
14 |
Correct |
6 ms |
5208 KB |
Output is correct |
15 |
Correct |
7 ms |
5208 KB |
Output is correct |
16 |
Correct |
7 ms |
5268 KB |
Output is correct |
17 |
Correct |
7 ms |
5260 KB |
Output is correct |
18 |
Correct |
6 ms |
5208 KB |
Output is correct |
19 |
Correct |
6 ms |
5264 KB |
Output is correct |
20 |
Correct |
6 ms |
5208 KB |
Output is correct |
21 |
Correct |
6 ms |
5208 KB |
Output is correct |
22 |
Correct |
4 ms |
5208 KB |
Output is correct |
23 |
Correct |
4 ms |
5208 KB |
Output is correct |
24 |
Correct |
7 ms |
5260 KB |
Output is correct |
25 |
Correct |
7 ms |
5208 KB |
Output is correct |
26 |
Correct |
7 ms |
5204 KB |
Output is correct |
27 |
Correct |
7 ms |
5208 KB |
Output is correct |
28 |
Correct |
7 ms |
5272 KB |
Output is correct |
29 |
Correct |
3 ms |
5236 KB |
Output is correct |
30 |
Correct |
3 ms |
5208 KB |
Output is correct |
31 |
Correct |
2 ms |
5208 KB |
Output is correct |
32 |
Correct |
7 ms |
5208 KB |
Output is correct |
33 |
Correct |
5 ms |
5208 KB |
Output is correct |
34 |
Correct |
3 ms |
5208 KB |
Output is correct |
35 |
Correct |
2 ms |
5208 KB |
Output is correct |
36 |
Correct |
6 ms |
5208 KB |
Output is correct |
37 |
Correct |
5 ms |
5284 KB |
Output is correct |
38 |
Correct |
5 ms |
5208 KB |
Output is correct |
39 |
Correct |
4 ms |
5208 KB |
Output is correct |
40 |
Correct |
4 ms |
5208 KB |
Output is correct |
41 |
Correct |
4 ms |
5208 KB |
Output is correct |
42 |
Correct |
2 ms |
5208 KB |
Output is correct |
43 |
Correct |
517 ms |
5456 KB |
Output is correct |
44 |
Correct |
647 ms |
5712 KB |
Output is correct |
45 |
Correct |
688 ms |
5712 KB |
Output is correct |
46 |
Correct |
807 ms |
5968 KB |
Output is correct |
47 |
Correct |
772 ms |
5884 KB |
Output is correct |
48 |
Correct |
815 ms |
5900 KB |
Output is correct |
49 |
Correct |
807 ms |
5884 KB |
Output is correct |
50 |
Correct |
783 ms |
5912 KB |
Output is correct |
51 |
Correct |
662 ms |
5792 KB |
Output is correct |
52 |
Correct |
656 ms |
5892 KB |
Output is correct |
53 |
Correct |
639 ms |
5464 KB |
Output is correct |
54 |
Correct |
839 ms |
6104 KB |
Output is correct |
55 |
Correct |
708 ms |
5968 KB |
Output is correct |
56 |
Correct |
674 ms |
5712 KB |
Output is correct |
57 |
Correct |
639 ms |
5720 KB |
Output is correct |
58 |
Correct |
764 ms |
5884 KB |
Output is correct |
59 |
Correct |
731 ms |
6176 KB |
Output is correct |
60 |
Correct |
726 ms |
6068 KB |
Output is correct |
61 |
Correct |
703 ms |
5712 KB |
Output is correct |
62 |
Correct |
686 ms |
5456 KB |
Output is correct |
63 |
Correct |
692 ms |
5464 KB |
Output is correct |
64 |
Correct |
686 ms |
5720 KB |
Output is correct |
65 |
Correct |
357 ms |
5364 KB |
Output is correct |
66 |
Correct |
758 ms |
5968 KB |
Output is correct |
67 |
Correct |
771 ms |
5712 KB |
Output is correct |
68 |
Correct |
682 ms |
5712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4952 KB |
Output is correct |
3 |
Correct |
2 ms |
5208 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 |
2 ms |
5208 KB |
Output is correct |
9 |
Correct |
3 ms |
4952 KB |
Output is correct |
10 |
Correct |
4 ms |
5208 KB |
Output is correct |
11 |
Correct |
3 ms |
5208 KB |
Output is correct |
12 |
Correct |
4 ms |
5208 KB |
Output is correct |
13 |
Correct |
3 ms |
5208 KB |
Output is correct |
14 |
Correct |
6 ms |
5208 KB |
Output is correct |
15 |
Correct |
7 ms |
5208 KB |
Output is correct |
16 |
Correct |
7 ms |
5268 KB |
Output is correct |
17 |
Correct |
7 ms |
5260 KB |
Output is correct |
18 |
Correct |
6 ms |
5208 KB |
Output is correct |
19 |
Correct |
6 ms |
5264 KB |
Output is correct |
20 |
Correct |
6 ms |
5208 KB |
Output is correct |
21 |
Correct |
6 ms |
5208 KB |
Output is correct |
22 |
Correct |
4 ms |
5208 KB |
Output is correct |
23 |
Correct |
4 ms |
5208 KB |
Output is correct |
24 |
Correct |
7 ms |
5260 KB |
Output is correct |
25 |
Correct |
7 ms |
5208 KB |
Output is correct |
26 |
Correct |
7 ms |
5204 KB |
Output is correct |
27 |
Correct |
7 ms |
5208 KB |
Output is correct |
28 |
Correct |
7 ms |
5272 KB |
Output is correct |
29 |
Correct |
3 ms |
5236 KB |
Output is correct |
30 |
Correct |
3 ms |
5208 KB |
Output is correct |
31 |
Correct |
2 ms |
5208 KB |
Output is correct |
32 |
Correct |
7 ms |
5208 KB |
Output is correct |
33 |
Correct |
5 ms |
5208 KB |
Output is correct |
34 |
Correct |
3 ms |
5208 KB |
Output is correct |
35 |
Correct |
2 ms |
5208 KB |
Output is correct |
36 |
Correct |
6 ms |
5208 KB |
Output is correct |
37 |
Correct |
5 ms |
5284 KB |
Output is correct |
38 |
Correct |
5 ms |
5208 KB |
Output is correct |
39 |
Correct |
4 ms |
5208 KB |
Output is correct |
40 |
Correct |
4 ms |
5208 KB |
Output is correct |
41 |
Correct |
4 ms |
5208 KB |
Output is correct |
42 |
Correct |
2 ms |
5208 KB |
Output is correct |
43 |
Execution timed out |
3063 ms |
8252 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |