#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
const long long mod=1'000'002'022;
long long pot2[200010];
long long iloL[200010], iloR[200010], ilo[200010];
vector<int>graf[200010];
long long policz(int n){
return pot2[n-1];
}
long long wsp[200010];
void dfs1(int x){
ilo[x] = 1;
if(graf[x].size())
ilo[x] = graf[x].size();
for(auto j: graf[x]){
dfs1(j);
ilo[x] = ilo[j]*ilo[x]%mod;
}
long long pom = 1;
for(int i=0;i<(int)graf[x].size();i++){
pom = pom*ilo[graf[x][i]]%mod;
iloL[graf[x][i]] = pom;
}
pom = 1;
for(int i=(int)graf[x].size()-1;i>=0;i--){
pom = pom*ilo[graf[x][i]]%mod;
iloR[graf[x][i]] = pom;
}
}
void dfs(int x, long long ilo){
if(graf[x].size()==0){
wsp[x] = ilo;
}
for(int i=0;i<(int)graf[x].size();i++){
long long pom = ilo;
if(i!=0)
pom = (pom*iloL[graf[x][i-1]])%mod;
if(i!=(int)graf[x].size()-1)
pom = (pom*iloR[graf[x][i+1]])%mod;
dfs(graf[x][i], pom);
}
}
struct node{long long val1, val2;bool czy;};
const int base = 1<<17;
node tree[2*base];
int M, N;
void change(int w, int l, int p, int a, int b){
if(l>b || p<a)return;
if(a<=l && p<=b){
swap(tree[w].val1, tree[w].val2);
tree[w].czy^=1;
return;
}
if(tree[w].czy){
swap(tree[w*2].val1, tree[w*2].val2);
swap(tree[w*2+1].val1, tree[w*2+1].val2);
tree[w*2].czy^=1;
tree[w*2+1].czy^=1;
tree[w].czy = 0;
}
change(w*2, l, (l+p)/2, a, b);
change(w*2+1, (l+p)/2+1, p, a, b);
tree[w].val1 = tree[w*2].val1+tree[w*2+1].val1;
tree[w].val2 = tree[w*2].val2+tree[w*2+1].val2;
}
void init(int n, int m, std::vector<int> P, std::vector<int> A) {
M = m;
N = n;
int i;
pot2[0] = 1;
for(int i=1;i<=n+m;i++)pot2[i] = pot2[i-1]*2%mod;
for(int i=1;i<n+m;i++)
graf[P[i]].push_back(i);
wsp[0] = 1;
dfs1(0);
dfs(0, 1);
// for(i=0;i<m;i++)
// printf("%lld ", wsp[i+n]);printf("\n");
// for(i=0;i<m+n;i++)
// printf("%lld ", ilo[i]);printf("\n");
for(int i=0;i<m;i++){
tree[i+base].val1 = wsp[i+n]*A[i];
tree[i+base].val2 = wsp[i+n]*(A[i]^1);
}
for(int i=base-1;i>0;i--){
tree[i].val1 = (tree[i*2].val1+tree[i*2+1].val1)%mod;
tree[i].val2 = (tree[i*2].val2+tree[i*2+1].val2)%mod;
}
// for(int i=0;i<M;i++)
// printf("%lld ", tree[i+base].val1);printf("\n");
}
int count_ways(int L, int R) {
change(1, 0, base-1, L-N, R-N);
return tree[1].val1%mod;
}
Compilation message
circuit.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>)':
circuit.cpp:73:6: warning: unused variable 'i' [-Wunused-variable]
73 | int i;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
19032 KB |
Output is correct |
2 |
Correct |
2 ms |
19032 KB |
Output is correct |
3 |
Correct |
2 ms |
19032 KB |
Output is correct |
4 |
Correct |
2 ms |
19032 KB |
Output is correct |
5 |
Correct |
3 ms |
19032 KB |
Output is correct |
6 |
Correct |
2 ms |
18904 KB |
Output is correct |
7 |
Correct |
3 ms |
19032 KB |
Output is correct |
8 |
Correct |
2 ms |
19032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
19032 KB |
Output is correct |
2 |
Correct |
2 ms |
19032 KB |
Output is correct |
3 |
Correct |
2 ms |
19032 KB |
Output is correct |
4 |
Correct |
2 ms |
19032 KB |
Output is correct |
5 |
Correct |
2 ms |
19032 KB |
Output is correct |
6 |
Correct |
2 ms |
19032 KB |
Output is correct |
7 |
Correct |
3 ms |
18948 KB |
Output is correct |
8 |
Correct |
3 ms |
19032 KB |
Output is correct |
9 |
Correct |
3 ms |
19032 KB |
Output is correct |
10 |
Correct |
3 ms |
19004 KB |
Output is correct |
11 |
Correct |
3 ms |
19032 KB |
Output is correct |
12 |
Correct |
3 ms |
19032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
19032 KB |
Output is correct |
2 |
Correct |
2 ms |
19032 KB |
Output is correct |
3 |
Correct |
2 ms |
19032 KB |
Output is correct |
4 |
Correct |
2 ms |
19032 KB |
Output is correct |
5 |
Correct |
3 ms |
19032 KB |
Output is correct |
6 |
Correct |
2 ms |
18904 KB |
Output is correct |
7 |
Correct |
3 ms |
19032 KB |
Output is correct |
8 |
Correct |
2 ms |
19032 KB |
Output is correct |
9 |
Correct |
2 ms |
19032 KB |
Output is correct |
10 |
Correct |
2 ms |
19032 KB |
Output is correct |
11 |
Correct |
2 ms |
19032 KB |
Output is correct |
12 |
Correct |
2 ms |
19032 KB |
Output is correct |
13 |
Correct |
2 ms |
19032 KB |
Output is correct |
14 |
Correct |
2 ms |
19032 KB |
Output is correct |
15 |
Correct |
3 ms |
18948 KB |
Output is correct |
16 |
Correct |
3 ms |
19032 KB |
Output is correct |
17 |
Correct |
3 ms |
19032 KB |
Output is correct |
18 |
Correct |
3 ms |
19004 KB |
Output is correct |
19 |
Correct |
3 ms |
19032 KB |
Output is correct |
20 |
Correct |
3 ms |
19032 KB |
Output is correct |
21 |
Correct |
3 ms |
19032 KB |
Output is correct |
22 |
Correct |
2 ms |
19032 KB |
Output is correct |
23 |
Correct |
2 ms |
19032 KB |
Output is correct |
24 |
Correct |
2 ms |
18956 KB |
Output is correct |
25 |
Correct |
3 ms |
19032 KB |
Output is correct |
26 |
Correct |
3 ms |
19032 KB |
Output is correct |
27 |
Correct |
3 ms |
19032 KB |
Output is correct |
28 |
Correct |
2 ms |
19032 KB |
Output is correct |
29 |
Correct |
2 ms |
19032 KB |
Output is correct |
30 |
Correct |
2 ms |
19032 KB |
Output is correct |
31 |
Correct |
3 ms |
19032 KB |
Output is correct |
32 |
Correct |
3 ms |
19032 KB |
Output is correct |
33 |
Correct |
3 ms |
19032 KB |
Output is correct |
34 |
Correct |
3 ms |
19032 KB |
Output is correct |
35 |
Correct |
3 ms |
19032 KB |
Output is correct |
36 |
Correct |
3 ms |
19032 KB |
Output is correct |
37 |
Correct |
2 ms |
19008 KB |
Output is correct |
38 |
Correct |
3 ms |
19016 KB |
Output is correct |
39 |
Correct |
3 ms |
19032 KB |
Output is correct |
40 |
Correct |
2 ms |
19032 KB |
Output is correct |
41 |
Correct |
3 ms |
19032 KB |
Output is correct |
42 |
Correct |
3 ms |
19032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
451 ms |
20816 KB |
Output is correct |
2 |
Correct |
649 ms |
22616 KB |
Output is correct |
3 |
Correct |
677 ms |
22484 KB |
Output is correct |
4 |
Correct |
595 ms |
22616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
451 ms |
20816 KB |
Output is correct |
2 |
Correct |
649 ms |
22616 KB |
Output is correct |
3 |
Correct |
677 ms |
22484 KB |
Output is correct |
4 |
Correct |
595 ms |
22616 KB |
Output is correct |
5 |
Correct |
537 ms |
20824 KB |
Output is correct |
6 |
Correct |
682 ms |
22616 KB |
Output is correct |
7 |
Correct |
641 ms |
22616 KB |
Output is correct |
8 |
Correct |
648 ms |
22616 KB |
Output is correct |
9 |
Correct |
344 ms |
19032 KB |
Output is correct |
10 |
Correct |
616 ms |
19288 KB |
Output is correct |
11 |
Correct |
676 ms |
19044 KB |
Output is correct |
12 |
Correct |
601 ms |
19288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
19032 KB |
Output is correct |
2 |
Correct |
2 ms |
19032 KB |
Output is correct |
3 |
Correct |
2 ms |
19032 KB |
Output is correct |
4 |
Correct |
2 ms |
19032 KB |
Output is correct |
5 |
Correct |
2 ms |
19032 KB |
Output is correct |
6 |
Correct |
2 ms |
19032 KB |
Output is correct |
7 |
Correct |
3 ms |
18948 KB |
Output is correct |
8 |
Correct |
3 ms |
19032 KB |
Output is correct |
9 |
Correct |
3 ms |
19032 KB |
Output is correct |
10 |
Correct |
3 ms |
19004 KB |
Output is correct |
11 |
Correct |
3 ms |
19032 KB |
Output is correct |
12 |
Correct |
3 ms |
19032 KB |
Output is correct |
13 |
Correct |
451 ms |
20816 KB |
Output is correct |
14 |
Correct |
649 ms |
22616 KB |
Output is correct |
15 |
Correct |
677 ms |
22484 KB |
Output is correct |
16 |
Correct |
595 ms |
22616 KB |
Output is correct |
17 |
Correct |
537 ms |
20824 KB |
Output is correct |
18 |
Correct |
682 ms |
22616 KB |
Output is correct |
19 |
Correct |
641 ms |
22616 KB |
Output is correct |
20 |
Correct |
648 ms |
22616 KB |
Output is correct |
21 |
Correct |
344 ms |
19032 KB |
Output is correct |
22 |
Correct |
616 ms |
19288 KB |
Output is correct |
23 |
Correct |
676 ms |
19044 KB |
Output is correct |
24 |
Correct |
601 ms |
19288 KB |
Output is correct |
25 |
Correct |
634 ms |
24400 KB |
Output is correct |
26 |
Correct |
772 ms |
24416 KB |
Output is correct |
27 |
Correct |
726 ms |
24400 KB |
Output is correct |
28 |
Correct |
576 ms |
24412 KB |
Output is correct |
29 |
Correct |
722 ms |
30796 KB |
Output is correct |
30 |
Correct |
647 ms |
30668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
19032 KB |
Output is correct |
2 |
Correct |
2 ms |
19032 KB |
Output is correct |
3 |
Correct |
2 ms |
19032 KB |
Output is correct |
4 |
Correct |
2 ms |
19032 KB |
Output is correct |
5 |
Correct |
3 ms |
19032 KB |
Output is correct |
6 |
Correct |
2 ms |
18904 KB |
Output is correct |
7 |
Correct |
3 ms |
19032 KB |
Output is correct |
8 |
Correct |
2 ms |
19032 KB |
Output is correct |
9 |
Correct |
2 ms |
19032 KB |
Output is correct |
10 |
Correct |
2 ms |
19032 KB |
Output is correct |
11 |
Correct |
2 ms |
19032 KB |
Output is correct |
12 |
Correct |
2 ms |
19032 KB |
Output is correct |
13 |
Correct |
2 ms |
19032 KB |
Output is correct |
14 |
Correct |
2 ms |
19032 KB |
Output is correct |
15 |
Correct |
3 ms |
18948 KB |
Output is correct |
16 |
Correct |
3 ms |
19032 KB |
Output is correct |
17 |
Correct |
3 ms |
19032 KB |
Output is correct |
18 |
Correct |
3 ms |
19004 KB |
Output is correct |
19 |
Correct |
3 ms |
19032 KB |
Output is correct |
20 |
Correct |
3 ms |
19032 KB |
Output is correct |
21 |
Correct |
3 ms |
19032 KB |
Output is correct |
22 |
Correct |
2 ms |
19032 KB |
Output is correct |
23 |
Correct |
2 ms |
19032 KB |
Output is correct |
24 |
Correct |
2 ms |
18956 KB |
Output is correct |
25 |
Correct |
3 ms |
19032 KB |
Output is correct |
26 |
Correct |
3 ms |
19032 KB |
Output is correct |
27 |
Correct |
3 ms |
19032 KB |
Output is correct |
28 |
Correct |
2 ms |
19032 KB |
Output is correct |
29 |
Correct |
2 ms |
19032 KB |
Output is correct |
30 |
Correct |
2 ms |
19032 KB |
Output is correct |
31 |
Correct |
3 ms |
19032 KB |
Output is correct |
32 |
Correct |
3 ms |
19032 KB |
Output is correct |
33 |
Correct |
3 ms |
19032 KB |
Output is correct |
34 |
Correct |
3 ms |
19032 KB |
Output is correct |
35 |
Correct |
3 ms |
19032 KB |
Output is correct |
36 |
Correct |
3 ms |
19032 KB |
Output is correct |
37 |
Correct |
2 ms |
19008 KB |
Output is correct |
38 |
Correct |
3 ms |
19016 KB |
Output is correct |
39 |
Correct |
3 ms |
19032 KB |
Output is correct |
40 |
Correct |
2 ms |
19032 KB |
Output is correct |
41 |
Correct |
3 ms |
19032 KB |
Output is correct |
42 |
Correct |
3 ms |
19032 KB |
Output is correct |
43 |
Correct |
454 ms |
19032 KB |
Output is correct |
44 |
Correct |
641 ms |
19032 KB |
Output is correct |
45 |
Correct |
637 ms |
19032 KB |
Output is correct |
46 |
Correct |
617 ms |
19288 KB |
Output is correct |
47 |
Correct |
594 ms |
19288 KB |
Output is correct |
48 |
Correct |
649 ms |
19288 KB |
Output is correct |
49 |
Correct |
685 ms |
19288 KB |
Output is correct |
50 |
Correct |
591 ms |
19288 KB |
Output is correct |
51 |
Correct |
665 ms |
19032 KB |
Output is correct |
52 |
Correct |
647 ms |
19032 KB |
Output is correct |
53 |
Correct |
607 ms |
19544 KB |
Output is correct |
54 |
Correct |
657 ms |
19288 KB |
Output is correct |
55 |
Correct |
644 ms |
19032 KB |
Output is correct |
56 |
Correct |
658 ms |
19032 KB |
Output is correct |
57 |
Correct |
631 ms |
19032 KB |
Output is correct |
58 |
Correct |
638 ms |
19544 KB |
Output is correct |
59 |
Correct |
655 ms |
19696 KB |
Output is correct |
60 |
Correct |
588 ms |
19688 KB |
Output is correct |
61 |
Correct |
622 ms |
19288 KB |
Output is correct |
62 |
Correct |
673 ms |
19032 KB |
Output is correct |
63 |
Correct |
637 ms |
19032 KB |
Output is correct |
64 |
Correct |
641 ms |
19032 KB |
Output is correct |
65 |
Correct |
333 ms |
19032 KB |
Output is correct |
66 |
Correct |
663 ms |
19288 KB |
Output is correct |
67 |
Correct |
616 ms |
19288 KB |
Output is correct |
68 |
Correct |
665 ms |
19288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
19032 KB |
Output is correct |
2 |
Correct |
2 ms |
19032 KB |
Output is correct |
3 |
Correct |
2 ms |
19032 KB |
Output is correct |
4 |
Correct |
2 ms |
19032 KB |
Output is correct |
5 |
Correct |
3 ms |
19032 KB |
Output is correct |
6 |
Correct |
2 ms |
18904 KB |
Output is correct |
7 |
Correct |
3 ms |
19032 KB |
Output is correct |
8 |
Correct |
2 ms |
19032 KB |
Output is correct |
9 |
Correct |
2 ms |
19032 KB |
Output is correct |
10 |
Correct |
2 ms |
19032 KB |
Output is correct |
11 |
Correct |
2 ms |
19032 KB |
Output is correct |
12 |
Correct |
2 ms |
19032 KB |
Output is correct |
13 |
Correct |
2 ms |
19032 KB |
Output is correct |
14 |
Correct |
2 ms |
19032 KB |
Output is correct |
15 |
Correct |
3 ms |
18948 KB |
Output is correct |
16 |
Correct |
3 ms |
19032 KB |
Output is correct |
17 |
Correct |
3 ms |
19032 KB |
Output is correct |
18 |
Correct |
3 ms |
19004 KB |
Output is correct |
19 |
Correct |
3 ms |
19032 KB |
Output is correct |
20 |
Correct |
3 ms |
19032 KB |
Output is correct |
21 |
Correct |
3 ms |
19032 KB |
Output is correct |
22 |
Correct |
2 ms |
19032 KB |
Output is correct |
23 |
Correct |
2 ms |
19032 KB |
Output is correct |
24 |
Correct |
2 ms |
18956 KB |
Output is correct |
25 |
Correct |
3 ms |
19032 KB |
Output is correct |
26 |
Correct |
3 ms |
19032 KB |
Output is correct |
27 |
Correct |
3 ms |
19032 KB |
Output is correct |
28 |
Correct |
2 ms |
19032 KB |
Output is correct |
29 |
Correct |
2 ms |
19032 KB |
Output is correct |
30 |
Correct |
2 ms |
19032 KB |
Output is correct |
31 |
Correct |
3 ms |
19032 KB |
Output is correct |
32 |
Correct |
3 ms |
19032 KB |
Output is correct |
33 |
Correct |
3 ms |
19032 KB |
Output is correct |
34 |
Correct |
3 ms |
19032 KB |
Output is correct |
35 |
Correct |
3 ms |
19032 KB |
Output is correct |
36 |
Correct |
3 ms |
19032 KB |
Output is correct |
37 |
Correct |
2 ms |
19008 KB |
Output is correct |
38 |
Correct |
3 ms |
19016 KB |
Output is correct |
39 |
Correct |
3 ms |
19032 KB |
Output is correct |
40 |
Correct |
2 ms |
19032 KB |
Output is correct |
41 |
Correct |
3 ms |
19032 KB |
Output is correct |
42 |
Correct |
3 ms |
19032 KB |
Output is correct |
43 |
Correct |
451 ms |
20816 KB |
Output is correct |
44 |
Correct |
649 ms |
22616 KB |
Output is correct |
45 |
Correct |
677 ms |
22484 KB |
Output is correct |
46 |
Correct |
595 ms |
22616 KB |
Output is correct |
47 |
Correct |
537 ms |
20824 KB |
Output is correct |
48 |
Correct |
682 ms |
22616 KB |
Output is correct |
49 |
Correct |
641 ms |
22616 KB |
Output is correct |
50 |
Correct |
648 ms |
22616 KB |
Output is correct |
51 |
Correct |
344 ms |
19032 KB |
Output is correct |
52 |
Correct |
616 ms |
19288 KB |
Output is correct |
53 |
Correct |
676 ms |
19044 KB |
Output is correct |
54 |
Correct |
601 ms |
19288 KB |
Output is correct |
55 |
Correct |
634 ms |
24400 KB |
Output is correct |
56 |
Correct |
772 ms |
24416 KB |
Output is correct |
57 |
Correct |
726 ms |
24400 KB |
Output is correct |
58 |
Correct |
576 ms |
24412 KB |
Output is correct |
59 |
Correct |
722 ms |
30796 KB |
Output is correct |
60 |
Correct |
647 ms |
30668 KB |
Output is correct |
61 |
Correct |
454 ms |
19032 KB |
Output is correct |
62 |
Correct |
641 ms |
19032 KB |
Output is correct |
63 |
Correct |
637 ms |
19032 KB |
Output is correct |
64 |
Correct |
617 ms |
19288 KB |
Output is correct |
65 |
Correct |
594 ms |
19288 KB |
Output is correct |
66 |
Correct |
649 ms |
19288 KB |
Output is correct |
67 |
Correct |
685 ms |
19288 KB |
Output is correct |
68 |
Correct |
591 ms |
19288 KB |
Output is correct |
69 |
Correct |
665 ms |
19032 KB |
Output is correct |
70 |
Correct |
647 ms |
19032 KB |
Output is correct |
71 |
Correct |
607 ms |
19544 KB |
Output is correct |
72 |
Correct |
657 ms |
19288 KB |
Output is correct |
73 |
Correct |
644 ms |
19032 KB |
Output is correct |
74 |
Correct |
658 ms |
19032 KB |
Output is correct |
75 |
Correct |
631 ms |
19032 KB |
Output is correct |
76 |
Correct |
638 ms |
19544 KB |
Output is correct |
77 |
Correct |
655 ms |
19696 KB |
Output is correct |
78 |
Correct |
588 ms |
19688 KB |
Output is correct |
79 |
Correct |
622 ms |
19288 KB |
Output is correct |
80 |
Correct |
673 ms |
19032 KB |
Output is correct |
81 |
Correct |
637 ms |
19032 KB |
Output is correct |
82 |
Correct |
641 ms |
19032 KB |
Output is correct |
83 |
Correct |
333 ms |
19032 KB |
Output is correct |
84 |
Correct |
663 ms |
19288 KB |
Output is correct |
85 |
Correct |
616 ms |
19288 KB |
Output is correct |
86 |
Correct |
665 ms |
19288 KB |
Output is correct |
87 |
Correct |
2 ms |
19032 KB |
Output is correct |
88 |
Correct |
433 ms |
23992 KB |
Output is correct |
89 |
Correct |
782 ms |
22700 KB |
Output is correct |
90 |
Correct |
746 ms |
22420 KB |
Output is correct |
91 |
Correct |
718 ms |
24540 KB |
Output is correct |
92 |
Correct |
738 ms |
24656 KB |
Output is correct |
93 |
Correct |
777 ms |
24656 KB |
Output is correct |
94 |
Correct |
696 ms |
24656 KB |
Output is correct |
95 |
Correct |
653 ms |
24656 KB |
Output is correct |
96 |
Correct |
597 ms |
20944 KB |
Output is correct |
97 |
Correct |
686 ms |
20944 KB |
Output is correct |
98 |
Correct |
621 ms |
29016 KB |
Output is correct |
99 |
Correct |
695 ms |
24420 KB |
Output is correct |
100 |
Correct |
731 ms |
22428 KB |
Output is correct |
101 |
Correct |
726 ms |
22096 KB |
Output is correct |
102 |
Correct |
669 ms |
21080 KB |
Output is correct |
103 |
Correct |
709 ms |
30796 KB |
Output is correct |
104 |
Correct |
731 ms |
31200 KB |
Output is correct |
105 |
Correct |
670 ms |
31188 KB |
Output is correct |
106 |
Correct |
696 ms |
23896 KB |
Output is correct |
107 |
Correct |
634 ms |
21580 KB |
Output is correct |
108 |
Correct |
680 ms |
21592 KB |
Output is correct |
109 |
Correct |
775 ms |
21076 KB |
Output is correct |