#include "circuit.h"
#include <vector>
const int MOD = 1000002022;
using namespace std;
struct node {
long long s, x = 1;
vector<node*> l;
};
void dfs(node* n){
if(n->l.empty()){
n->s = 1;
}else n->s = n->l.size();
for(node* c : n->l){
dfs(c);
n->s = n->s*c->s%MOD;
}
}
void dfx(node* n){
if(n->l.empty()) return;
long long x = n->x;
for(node* c : n->l){
c->x = c->x*x%MOD;
x = (x*c->s)%MOD;
}
x = 1;
for(int i = n->l.size()-1;i >= 0;i--){
node*c = n->l[i];
c->x = c->x * x %MOD;
x = (x*c->s)%MOD;
dfx(c);
}
}
const int nx = 4e5+10;
int st[nx], su[nx];bool lz[nx] = {false};
int n;
int cons(int i, int l, int r, const vector<int>& A, node g[]){
if(l==r){
if(A[l-n]) st[i] = g[l].x;
else st[i]=0;
su[i]=g[l].x;
return st[i];
}
int m = l+r>>1;
st[i] = (cons(i<<1, l, m, A, g)+cons(i<<1|1, m+1, r, A, g))%MOD;
su[i] = (su[i<<1]+su[i<<1|1])%MOD;
return st[i];
}
void upd(int i, int l, int r, int a, int b){
if(lz[i]){
st[i] = (su[i]-st[i]+MOD)%MOD;
if(l!=r){
lz[i<<1] ^= 1;
lz[i<<1|1] ^= 1;
}
lz[i]=false;
}
if(b < l || r < a) return;
if(a <= l && r <= b){
st[i] = (su[i]-st[i]+MOD)%MOD;
if(l!=r){
lz[i<<1] ^= 1;
lz[i<<1|1] ^= 1;
}
return;
}
int m = l+r>>1;
upd(i<<1, l, m, a, b);upd(i<<1|1, m+1, r, a, b);
st[i] = (st[i<<1]+st[i<<1|1])%MOD;
}
int nm;
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
node g[N+M];
nm = N+M-1;
n = N;
for(int i = 1;i < N+M;i++){
g[P[i]].l.push_back(&g[i]);
}
dfs(&g[0]);
dfx(&g[0]);
cons(1, N, N+M-1, A, g);
}
int count_ways(int L, int R) {
upd(1, n, nm, L, R);
return st[1];
}
Compilation message
circuit.cpp: In function 'int cons(int, int, int, const std::vector<int>&, node*)':
circuit.cpp:44:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
44 | int m = l+r>>1;
| ~^~
circuit.cpp: In function 'void upd(int, int, int, int, int)':
circuit.cpp:67:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
67 | int m = l+r>>1;
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
464 KB |
Output is correct |
10 |
Correct |
0 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
464 KB |
Output is correct |
18 |
Correct |
0 ms |
600 KB |
Output is correct |
19 |
Correct |
1 ms |
600 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
0 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
344 KB |
Output is correct |
36 |
Correct |
1 ms |
600 KB |
Output is correct |
37 |
Correct |
1 ms |
600 KB |
Output is correct |
38 |
Correct |
1 ms |
600 KB |
Output is correct |
39 |
Correct |
1 ms |
344 KB |
Output is correct |
40 |
Correct |
0 ms |
344 KB |
Output is correct |
41 |
Correct |
1 ms |
344 KB |
Output is correct |
42 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
444 ms |
5208 KB |
Output is correct |
2 |
Correct |
683 ms |
10196 KB |
Output is correct |
3 |
Correct |
607 ms |
10072 KB |
Output is correct |
4 |
Correct |
685 ms |
10072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
444 ms |
5208 KB |
Output is correct |
2 |
Correct |
683 ms |
10196 KB |
Output is correct |
3 |
Correct |
607 ms |
10072 KB |
Output is correct |
4 |
Correct |
685 ms |
10072 KB |
Output is correct |
5 |
Correct |
549 ms |
5208 KB |
Output is correct |
6 |
Correct |
670 ms |
10064 KB |
Output is correct |
7 |
Correct |
728 ms |
10072 KB |
Output is correct |
8 |
Correct |
694 ms |
10072 KB |
Output is correct |
9 |
Correct |
322 ms |
852 KB |
Output is correct |
10 |
Correct |
670 ms |
856 KB |
Output is correct |
11 |
Correct |
606 ms |
856 KB |
Output is correct |
12 |
Correct |
637 ms |
856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
464 KB |
Output is correct |
10 |
Correct |
0 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
444 ms |
5208 KB |
Output is correct |
14 |
Correct |
683 ms |
10196 KB |
Output is correct |
15 |
Correct |
607 ms |
10072 KB |
Output is correct |
16 |
Correct |
685 ms |
10072 KB |
Output is correct |
17 |
Correct |
549 ms |
5208 KB |
Output is correct |
18 |
Correct |
670 ms |
10064 KB |
Output is correct |
19 |
Correct |
728 ms |
10072 KB |
Output is correct |
20 |
Correct |
694 ms |
10072 KB |
Output is correct |
21 |
Correct |
322 ms |
852 KB |
Output is correct |
22 |
Correct |
670 ms |
856 KB |
Output is correct |
23 |
Correct |
606 ms |
856 KB |
Output is correct |
24 |
Correct |
637 ms |
856 KB |
Output is correct |
25 |
Correct |
694 ms |
15408 KB |
Output is correct |
26 |
Correct |
709 ms |
15696 KB |
Output is correct |
27 |
Correct |
753 ms |
15696 KB |
Output is correct |
28 |
Correct |
542 ms |
15696 KB |
Output is correct |
29 |
Correct |
737 ms |
20296 KB |
Output is correct |
30 |
Correct |
662 ms |
20392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
464 KB |
Output is correct |
18 |
Correct |
0 ms |
600 KB |
Output is correct |
19 |
Correct |
1 ms |
600 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
0 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
344 KB |
Output is correct |
36 |
Correct |
1 ms |
600 KB |
Output is correct |
37 |
Correct |
1 ms |
600 KB |
Output is correct |
38 |
Correct |
1 ms |
600 KB |
Output is correct |
39 |
Correct |
1 ms |
344 KB |
Output is correct |
40 |
Correct |
0 ms |
344 KB |
Output is correct |
41 |
Correct |
1 ms |
344 KB |
Output is correct |
42 |
Correct |
1 ms |
344 KB |
Output is correct |
43 |
Correct |
430 ms |
856 KB |
Output is correct |
44 |
Correct |
627 ms |
856 KB |
Output is correct |
45 |
Correct |
608 ms |
856 KB |
Output is correct |
46 |
Correct |
609 ms |
1112 KB |
Output is correct |
47 |
Correct |
610 ms |
1112 KB |
Output is correct |
48 |
Correct |
621 ms |
1112 KB |
Output is correct |
49 |
Correct |
701 ms |
1112 KB |
Output is correct |
50 |
Correct |
665 ms |
1112 KB |
Output is correct |
51 |
Correct |
583 ms |
856 KB |
Output is correct |
52 |
Correct |
601 ms |
856 KB |
Output is correct |
53 |
Correct |
616 ms |
856 KB |
Output is correct |
54 |
Correct |
578 ms |
1112 KB |
Output is correct |
55 |
Correct |
663 ms |
856 KB |
Output is correct |
56 |
Correct |
596 ms |
868 KB |
Output is correct |
57 |
Correct |
635 ms |
856 KB |
Output is correct |
58 |
Correct |
659 ms |
1368 KB |
Output is correct |
59 |
Correct |
645 ms |
1368 KB |
Output is correct |
60 |
Correct |
601 ms |
1368 KB |
Output is correct |
61 |
Correct |
629 ms |
856 KB |
Output is correct |
62 |
Correct |
604 ms |
856 KB |
Output is correct |
63 |
Correct |
675 ms |
856 KB |
Output is correct |
64 |
Correct |
626 ms |
856 KB |
Output is correct |
65 |
Correct |
306 ms |
600 KB |
Output is correct |
66 |
Correct |
611 ms |
856 KB |
Output is correct |
67 |
Correct |
617 ms |
856 KB |
Output is correct |
68 |
Correct |
595 ms |
856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
464 KB |
Output is correct |
18 |
Correct |
0 ms |
600 KB |
Output is correct |
19 |
Correct |
1 ms |
600 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
0 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
344 KB |
Output is correct |
36 |
Correct |
1 ms |
600 KB |
Output is correct |
37 |
Correct |
1 ms |
600 KB |
Output is correct |
38 |
Correct |
1 ms |
600 KB |
Output is correct |
39 |
Correct |
1 ms |
344 KB |
Output is correct |
40 |
Correct |
0 ms |
344 KB |
Output is correct |
41 |
Correct |
1 ms |
344 KB |
Output is correct |
42 |
Correct |
1 ms |
344 KB |
Output is correct |
43 |
Correct |
444 ms |
5208 KB |
Output is correct |
44 |
Correct |
683 ms |
10196 KB |
Output is correct |
45 |
Correct |
607 ms |
10072 KB |
Output is correct |
46 |
Correct |
685 ms |
10072 KB |
Output is correct |
47 |
Correct |
549 ms |
5208 KB |
Output is correct |
48 |
Correct |
670 ms |
10064 KB |
Output is correct |
49 |
Correct |
728 ms |
10072 KB |
Output is correct |
50 |
Correct |
694 ms |
10072 KB |
Output is correct |
51 |
Correct |
322 ms |
852 KB |
Output is correct |
52 |
Correct |
670 ms |
856 KB |
Output is correct |
53 |
Correct |
606 ms |
856 KB |
Output is correct |
54 |
Correct |
637 ms |
856 KB |
Output is correct |
55 |
Correct |
694 ms |
15408 KB |
Output is correct |
56 |
Correct |
709 ms |
15696 KB |
Output is correct |
57 |
Correct |
753 ms |
15696 KB |
Output is correct |
58 |
Correct |
542 ms |
15696 KB |
Output is correct |
59 |
Correct |
737 ms |
20296 KB |
Output is correct |
60 |
Correct |
662 ms |
20392 KB |
Output is correct |
61 |
Correct |
430 ms |
856 KB |
Output is correct |
62 |
Correct |
627 ms |
856 KB |
Output is correct |
63 |
Correct |
608 ms |
856 KB |
Output is correct |
64 |
Correct |
609 ms |
1112 KB |
Output is correct |
65 |
Correct |
610 ms |
1112 KB |
Output is correct |
66 |
Correct |
621 ms |
1112 KB |
Output is correct |
67 |
Correct |
701 ms |
1112 KB |
Output is correct |
68 |
Correct |
665 ms |
1112 KB |
Output is correct |
69 |
Correct |
583 ms |
856 KB |
Output is correct |
70 |
Correct |
601 ms |
856 KB |
Output is correct |
71 |
Correct |
616 ms |
856 KB |
Output is correct |
72 |
Correct |
578 ms |
1112 KB |
Output is correct |
73 |
Correct |
663 ms |
856 KB |
Output is correct |
74 |
Correct |
596 ms |
868 KB |
Output is correct |
75 |
Correct |
635 ms |
856 KB |
Output is correct |
76 |
Correct |
659 ms |
1368 KB |
Output is correct |
77 |
Correct |
645 ms |
1368 KB |
Output is correct |
78 |
Correct |
601 ms |
1368 KB |
Output is correct |
79 |
Correct |
629 ms |
856 KB |
Output is correct |
80 |
Correct |
604 ms |
856 KB |
Output is correct |
81 |
Correct |
675 ms |
856 KB |
Output is correct |
82 |
Correct |
626 ms |
856 KB |
Output is correct |
83 |
Correct |
306 ms |
600 KB |
Output is correct |
84 |
Correct |
611 ms |
856 KB |
Output is correct |
85 |
Correct |
617 ms |
856 KB |
Output is correct |
86 |
Correct |
595 ms |
856 KB |
Output is correct |
87 |
Correct |
0 ms |
344 KB |
Output is correct |
88 |
Correct |
387 ms |
14744 KB |
Output is correct |
89 |
Correct |
650 ms |
10068 KB |
Output is correct |
90 |
Correct |
652 ms |
10072 KB |
Output is correct |
91 |
Correct |
677 ms |
16208 KB |
Output is correct |
92 |
Correct |
753 ms |
16208 KB |
Output is correct |
93 |
Correct |
685 ms |
16208 KB |
Output is correct |
94 |
Correct |
731 ms |
16208 KB |
Output is correct |
95 |
Correct |
731 ms |
16208 KB |
Output is correct |
96 |
Correct |
675 ms |
8652 KB |
Output is correct |
97 |
Correct |
687 ms |
8652 KB |
Output is correct |
98 |
Correct |
614 ms |
12888 KB |
Output is correct |
99 |
Correct |
720 ms |
15696 KB |
Output is correct |
100 |
Correct |
713 ms |
12700 KB |
Output is correct |
101 |
Correct |
730 ms |
11088 KB |
Output is correct |
102 |
Correct |
700 ms |
8784 KB |
Output is correct |
103 |
Correct |
751 ms |
20300 KB |
Output is correct |
104 |
Correct |
680 ms |
21196 KB |
Output is correct |
105 |
Correct |
649 ms |
21196 KB |
Output is correct |
106 |
Correct |
682 ms |
10840 KB |
Output is correct |
107 |
Correct |
719 ms |
9552 KB |
Output is correct |
108 |
Correct |
696 ms |
9816 KB |
Output is correct |
109 |
Correct |
719 ms |
9040 KB |
Output is correct |