#include <bits/stdc++.h>
#include "circuit.h"
using namespace std;
const int N = 2e5 + 10 , mod = 1000002022;
int sbt[N] , n , m , zarib[N] , st_tim[N] , fn_tim[N] , tim;
vector <int> p , a , adj[N];
struct SEG1{
int t[N << 2];
void Build(int node = 1 , int nl = 0 , int nr = m)
{
t[node] = 1;
if(nr - nl == 1)
return;
int mid = (nl + nr) >> 1 , lc = node << 1 , rc = lc | 1;
Build(lc , nl , mid); Build(rc , mid , nr);
}
void Add(int val , int l , int r , int node = 1 , int nl = 0 , int nr = m)
{
if(r <= nl || nr <= l)
return;
if(l <= nl && nr <= r)
{
t[node] = 1LL * t[node] * val % mod;
return;
}
int mid = (nl + nr) >> 1 , lc = node << 1 , rc = lc | 1;
Add(val , l , r , lc , nl , mid); Add(val , l , r , rc , mid , nr);
}
int Get(int id , int node = 1 , int nl = 0 , int nr = m)
{
if(nr - nl == 1)
return t[node];
int mid = (nl + nr) >> 1 , lc = node << 1 , rc = lc | 1;
if(id < mid)
return 1LL * t[node] * Get(id , lc , nl , mid) % mod;
else
return 1LL * t[node] * Get(id , rc , mid , nr) % mod;
}
} seg1;
struct SEG{
int sum[2][N << 2];
int lzy_swp[N << 2];
void Build(int node = 1 , int nl = 0 , int nr = m)
{
lzy_swp[node] = 0;
if(nr - nl == 1)
{
sum[0][node] = sum[1][node] = 0;
sum[a[nl]][node] = seg1.Get(st_tim[nl + n]);
return;
}
int mid = (nl + nr) >> 1 , lc = node << 1 , rc = lc | 1;
Build(lc , nl , mid); Build(rc , mid , nr);
sum[0][node] = (sum[0][lc] + sum[0][rc]) % mod;
sum[1][node] = (sum[1][lc] + sum[1][rc]) % mod;
}
void Shift(int node , int lc , int rc)
{
if(!lzy_swp[node])
return;
lzy_swp[node] = 0;
swap(sum[0][lc] , sum[1][lc]);
swap(sum[0][rc] , sum[1][rc]);
lzy_swp[lc] ^= 1;
lzy_swp[rc] ^= 1;
}
void Update(int l , int r , int node = 1 , int nl = 0 , int nr = m)
{
if(r <= nl || nr <= l)
return;
if(l <= nl && nr <= r)
{
swap(sum[0][node] , sum[1][node]);
lzy_swp[node] ^= 1;
return;
}
int mid = (nl + nr) >> 1 , lc = node << 1 , rc = lc | 1;
Shift(node , lc , rc);
Update(l , r , lc , nl , mid);
Update(l , r , rc , mid , nr);
sum[0][node] = (sum[0][lc] + sum[0][rc]) % mod;
sum[1][node] = (sum[1][lc] + sum[1][rc]) % mod;
}
} seg;
void Find_sbt(int v)
{
sbt[v] = adj[v].size();
st_tim[v] = tim;
if(sbt[v] == 0)
{
sbt[v] = 1;
tim++;
fn_tim[v] = tim;
return;
}
for(auto u : adj[v])
{
Find_sbt(u);
sbt[v] = 1LL * sbt[v] * sbt[u] % mod;
}
fn_tim[v] = tim;
}
void Dfs(int v)
{
if(v >= n)
return;
for(int ty = 0 ; ty < 2 ; ty++)
{
int prf = 1;
for(auto u : adj[v])
{
seg1.Add(prf , st_tim[u] , fn_tim[u]);
prf = 1LL * prf * sbt[u] % mod;
}
reverse(adj[v].begin() , adj[v].end());
}
for(auto u : adj[v])
Dfs(u);
}
void init(int nn , int mm , vector <int> pp , vector <int> aa)
{
n = nn;
m = mm;
p = pp;
a = aa;
for(int i = 1 ; i < n + m ; i++)
adj[p[i]].push_back(i);
Find_sbt(0);
seg1.Build();
Dfs(0);
seg.Build();
}
int count_ways(int l , int r)
{
l -= n;
r -= n;
r++;
seg.Update(l , r);
return seg.sum[1][1];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12632 KB |
Output is correct |
2 |
Correct |
2 ms |
12632 KB |
Output is correct |
3 |
Correct |
2 ms |
12676 KB |
Output is correct |
4 |
Correct |
2 ms |
12632 KB |
Output is correct |
5 |
Correct |
2 ms |
12632 KB |
Output is correct |
6 |
Correct |
2 ms |
12632 KB |
Output is correct |
7 |
Correct |
2 ms |
12632 KB |
Output is correct |
8 |
Correct |
2 ms |
12632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12632 KB |
Output is correct |
2 |
Correct |
2 ms |
12632 KB |
Output is correct |
3 |
Correct |
2 ms |
12784 KB |
Output is correct |
4 |
Correct |
2 ms |
12632 KB |
Output is correct |
5 |
Correct |
2 ms |
12632 KB |
Output is correct |
6 |
Correct |
2 ms |
12632 KB |
Output is correct |
7 |
Correct |
2 ms |
12632 KB |
Output is correct |
8 |
Correct |
2 ms |
12632 KB |
Output is correct |
9 |
Correct |
3 ms |
12632 KB |
Output is correct |
10 |
Correct |
2 ms |
12888 KB |
Output is correct |
11 |
Correct |
2 ms |
12888 KB |
Output is correct |
12 |
Correct |
2 ms |
12632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12632 KB |
Output is correct |
2 |
Correct |
2 ms |
12632 KB |
Output is correct |
3 |
Correct |
2 ms |
12676 KB |
Output is correct |
4 |
Correct |
2 ms |
12632 KB |
Output is correct |
5 |
Correct |
2 ms |
12632 KB |
Output is correct |
6 |
Correct |
2 ms |
12632 KB |
Output is correct |
7 |
Correct |
2 ms |
12632 KB |
Output is correct |
8 |
Correct |
2 ms |
12632 KB |
Output is correct |
9 |
Correct |
2 ms |
12632 KB |
Output is correct |
10 |
Correct |
2 ms |
12632 KB |
Output is correct |
11 |
Correct |
2 ms |
12784 KB |
Output is correct |
12 |
Correct |
2 ms |
12632 KB |
Output is correct |
13 |
Correct |
2 ms |
12632 KB |
Output is correct |
14 |
Correct |
2 ms |
12632 KB |
Output is correct |
15 |
Correct |
2 ms |
12632 KB |
Output is correct |
16 |
Correct |
2 ms |
12632 KB |
Output is correct |
17 |
Correct |
3 ms |
12632 KB |
Output is correct |
18 |
Correct |
2 ms |
12888 KB |
Output is correct |
19 |
Correct |
2 ms |
12888 KB |
Output is correct |
20 |
Correct |
2 ms |
12632 KB |
Output is correct |
21 |
Correct |
2 ms |
12632 KB |
Output is correct |
22 |
Correct |
2 ms |
12632 KB |
Output is correct |
23 |
Correct |
2 ms |
12632 KB |
Output is correct |
24 |
Correct |
2 ms |
12632 KB |
Output is correct |
25 |
Correct |
2 ms |
12632 KB |
Output is correct |
26 |
Correct |
2 ms |
12632 KB |
Output is correct |
27 |
Correct |
2 ms |
12632 KB |
Output is correct |
28 |
Correct |
2 ms |
12824 KB |
Output is correct |
29 |
Correct |
2 ms |
12632 KB |
Output is correct |
30 |
Correct |
2 ms |
12632 KB |
Output is correct |
31 |
Correct |
2 ms |
12724 KB |
Output is correct |
32 |
Correct |
2 ms |
12824 KB |
Output is correct |
33 |
Correct |
2 ms |
12632 KB |
Output is correct |
34 |
Correct |
2 ms |
12632 KB |
Output is correct |
35 |
Correct |
2 ms |
12632 KB |
Output is correct |
36 |
Correct |
2 ms |
12880 KB |
Output is correct |
37 |
Correct |
2 ms |
12888 KB |
Output is correct |
38 |
Correct |
2 ms |
12888 KB |
Output is correct |
39 |
Correct |
2 ms |
12632 KB |
Output is correct |
40 |
Correct |
2 ms |
12632 KB |
Output is correct |
41 |
Correct |
2 ms |
12632 KB |
Output is correct |
42 |
Correct |
2 ms |
12632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
514 ms |
19288 KB |
Output is correct |
2 |
Correct |
725 ms |
21840 KB |
Output is correct |
3 |
Correct |
706 ms |
21732 KB |
Output is correct |
4 |
Correct |
719 ms |
21840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
514 ms |
19288 KB |
Output is correct |
2 |
Correct |
725 ms |
21840 KB |
Output is correct |
3 |
Correct |
706 ms |
21732 KB |
Output is correct |
4 |
Correct |
719 ms |
21840 KB |
Output is correct |
5 |
Correct |
582 ms |
19288 KB |
Output is correct |
6 |
Correct |
719 ms |
21840 KB |
Output is correct |
7 |
Correct |
678 ms |
21848 KB |
Output is correct |
8 |
Correct |
699 ms |
21840 KB |
Output is correct |
9 |
Correct |
321 ms |
12888 KB |
Output is correct |
10 |
Correct |
669 ms |
12888 KB |
Output is correct |
11 |
Correct |
604 ms |
12888 KB |
Output is correct |
12 |
Correct |
624 ms |
12888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12632 KB |
Output is correct |
2 |
Correct |
2 ms |
12632 KB |
Output is correct |
3 |
Correct |
2 ms |
12784 KB |
Output is correct |
4 |
Correct |
2 ms |
12632 KB |
Output is correct |
5 |
Correct |
2 ms |
12632 KB |
Output is correct |
6 |
Correct |
2 ms |
12632 KB |
Output is correct |
7 |
Correct |
2 ms |
12632 KB |
Output is correct |
8 |
Correct |
2 ms |
12632 KB |
Output is correct |
9 |
Correct |
3 ms |
12632 KB |
Output is correct |
10 |
Correct |
2 ms |
12888 KB |
Output is correct |
11 |
Correct |
2 ms |
12888 KB |
Output is correct |
12 |
Correct |
2 ms |
12632 KB |
Output is correct |
13 |
Correct |
514 ms |
19288 KB |
Output is correct |
14 |
Correct |
725 ms |
21840 KB |
Output is correct |
15 |
Correct |
706 ms |
21732 KB |
Output is correct |
16 |
Correct |
719 ms |
21840 KB |
Output is correct |
17 |
Correct |
582 ms |
19288 KB |
Output is correct |
18 |
Correct |
719 ms |
21840 KB |
Output is correct |
19 |
Correct |
678 ms |
21848 KB |
Output is correct |
20 |
Correct |
699 ms |
21840 KB |
Output is correct |
21 |
Correct |
321 ms |
12888 KB |
Output is correct |
22 |
Correct |
669 ms |
12888 KB |
Output is correct |
23 |
Correct |
604 ms |
12888 KB |
Output is correct |
24 |
Correct |
624 ms |
12888 KB |
Output is correct |
25 |
Correct |
763 ms |
24400 KB |
Output is correct |
26 |
Correct |
757 ms |
24676 KB |
Output is correct |
27 |
Correct |
797 ms |
24400 KB |
Output is correct |
28 |
Correct |
647 ms |
24404 KB |
Output is correct |
29 |
Correct |
757 ms |
36944 KB |
Output is correct |
30 |
Correct |
783 ms |
37092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12632 KB |
Output is correct |
2 |
Correct |
2 ms |
12632 KB |
Output is correct |
3 |
Correct |
2 ms |
12676 KB |
Output is correct |
4 |
Correct |
2 ms |
12632 KB |
Output is correct |
5 |
Correct |
2 ms |
12632 KB |
Output is correct |
6 |
Correct |
2 ms |
12632 KB |
Output is correct |
7 |
Correct |
2 ms |
12632 KB |
Output is correct |
8 |
Correct |
2 ms |
12632 KB |
Output is correct |
9 |
Correct |
2 ms |
12632 KB |
Output is correct |
10 |
Correct |
2 ms |
12632 KB |
Output is correct |
11 |
Correct |
2 ms |
12784 KB |
Output is correct |
12 |
Correct |
2 ms |
12632 KB |
Output is correct |
13 |
Correct |
2 ms |
12632 KB |
Output is correct |
14 |
Correct |
2 ms |
12632 KB |
Output is correct |
15 |
Correct |
2 ms |
12632 KB |
Output is correct |
16 |
Correct |
2 ms |
12632 KB |
Output is correct |
17 |
Correct |
3 ms |
12632 KB |
Output is correct |
18 |
Correct |
2 ms |
12888 KB |
Output is correct |
19 |
Correct |
2 ms |
12888 KB |
Output is correct |
20 |
Correct |
2 ms |
12632 KB |
Output is correct |
21 |
Correct |
2 ms |
12632 KB |
Output is correct |
22 |
Correct |
2 ms |
12632 KB |
Output is correct |
23 |
Correct |
2 ms |
12632 KB |
Output is correct |
24 |
Correct |
2 ms |
12632 KB |
Output is correct |
25 |
Correct |
2 ms |
12632 KB |
Output is correct |
26 |
Correct |
2 ms |
12632 KB |
Output is correct |
27 |
Correct |
2 ms |
12632 KB |
Output is correct |
28 |
Correct |
2 ms |
12824 KB |
Output is correct |
29 |
Correct |
2 ms |
12632 KB |
Output is correct |
30 |
Correct |
2 ms |
12632 KB |
Output is correct |
31 |
Correct |
2 ms |
12724 KB |
Output is correct |
32 |
Correct |
2 ms |
12824 KB |
Output is correct |
33 |
Correct |
2 ms |
12632 KB |
Output is correct |
34 |
Correct |
2 ms |
12632 KB |
Output is correct |
35 |
Correct |
2 ms |
12632 KB |
Output is correct |
36 |
Correct |
2 ms |
12880 KB |
Output is correct |
37 |
Correct |
2 ms |
12888 KB |
Output is correct |
38 |
Correct |
2 ms |
12888 KB |
Output is correct |
39 |
Correct |
2 ms |
12632 KB |
Output is correct |
40 |
Correct |
2 ms |
12632 KB |
Output is correct |
41 |
Correct |
2 ms |
12632 KB |
Output is correct |
42 |
Correct |
2 ms |
12632 KB |
Output is correct |
43 |
Correct |
422 ms |
12888 KB |
Output is correct |
44 |
Correct |
583 ms |
12888 KB |
Output is correct |
45 |
Correct |
615 ms |
12888 KB |
Output is correct |
46 |
Correct |
644 ms |
15192 KB |
Output is correct |
47 |
Correct |
671 ms |
15192 KB |
Output is correct |
48 |
Correct |
629 ms |
15192 KB |
Output is correct |
49 |
Correct |
644 ms |
15192 KB |
Output is correct |
50 |
Correct |
637 ms |
15188 KB |
Output is correct |
51 |
Correct |
651 ms |
14936 KB |
Output is correct |
52 |
Correct |
672 ms |
14936 KB |
Output is correct |
53 |
Correct |
538 ms |
13400 KB |
Output is correct |
54 |
Correct |
677 ms |
15188 KB |
Output is correct |
55 |
Correct |
645 ms |
14936 KB |
Output is correct |
56 |
Correct |
655 ms |
14936 KB |
Output is correct |
57 |
Correct |
640 ms |
14936 KB |
Output is correct |
58 |
Correct |
699 ms |
15704 KB |
Output is correct |
59 |
Correct |
630 ms |
15704 KB |
Output is correct |
60 |
Correct |
621 ms |
15704 KB |
Output is correct |
61 |
Correct |
666 ms |
13140 KB |
Output is correct |
62 |
Correct |
647 ms |
12888 KB |
Output is correct |
63 |
Correct |
623 ms |
12888 KB |
Output is correct |
64 |
Correct |
658 ms |
14936 KB |
Output is correct |
65 |
Correct |
309 ms |
12888 KB |
Output is correct |
66 |
Correct |
688 ms |
12888 KB |
Output is correct |
67 |
Correct |
665 ms |
12888 KB |
Output is correct |
68 |
Correct |
651 ms |
12888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12632 KB |
Output is correct |
2 |
Correct |
2 ms |
12632 KB |
Output is correct |
3 |
Correct |
2 ms |
12676 KB |
Output is correct |
4 |
Correct |
2 ms |
12632 KB |
Output is correct |
5 |
Correct |
2 ms |
12632 KB |
Output is correct |
6 |
Correct |
2 ms |
12632 KB |
Output is correct |
7 |
Correct |
2 ms |
12632 KB |
Output is correct |
8 |
Correct |
2 ms |
12632 KB |
Output is correct |
9 |
Correct |
2 ms |
12632 KB |
Output is correct |
10 |
Correct |
2 ms |
12632 KB |
Output is correct |
11 |
Correct |
2 ms |
12784 KB |
Output is correct |
12 |
Correct |
2 ms |
12632 KB |
Output is correct |
13 |
Correct |
2 ms |
12632 KB |
Output is correct |
14 |
Correct |
2 ms |
12632 KB |
Output is correct |
15 |
Correct |
2 ms |
12632 KB |
Output is correct |
16 |
Correct |
2 ms |
12632 KB |
Output is correct |
17 |
Correct |
3 ms |
12632 KB |
Output is correct |
18 |
Correct |
2 ms |
12888 KB |
Output is correct |
19 |
Correct |
2 ms |
12888 KB |
Output is correct |
20 |
Correct |
2 ms |
12632 KB |
Output is correct |
21 |
Correct |
2 ms |
12632 KB |
Output is correct |
22 |
Correct |
2 ms |
12632 KB |
Output is correct |
23 |
Correct |
2 ms |
12632 KB |
Output is correct |
24 |
Correct |
2 ms |
12632 KB |
Output is correct |
25 |
Correct |
2 ms |
12632 KB |
Output is correct |
26 |
Correct |
2 ms |
12632 KB |
Output is correct |
27 |
Correct |
2 ms |
12632 KB |
Output is correct |
28 |
Correct |
2 ms |
12824 KB |
Output is correct |
29 |
Correct |
2 ms |
12632 KB |
Output is correct |
30 |
Correct |
2 ms |
12632 KB |
Output is correct |
31 |
Correct |
2 ms |
12724 KB |
Output is correct |
32 |
Correct |
2 ms |
12824 KB |
Output is correct |
33 |
Correct |
2 ms |
12632 KB |
Output is correct |
34 |
Correct |
2 ms |
12632 KB |
Output is correct |
35 |
Correct |
2 ms |
12632 KB |
Output is correct |
36 |
Correct |
2 ms |
12880 KB |
Output is correct |
37 |
Correct |
2 ms |
12888 KB |
Output is correct |
38 |
Correct |
2 ms |
12888 KB |
Output is correct |
39 |
Correct |
2 ms |
12632 KB |
Output is correct |
40 |
Correct |
2 ms |
12632 KB |
Output is correct |
41 |
Correct |
2 ms |
12632 KB |
Output is correct |
42 |
Correct |
2 ms |
12632 KB |
Output is correct |
43 |
Correct |
514 ms |
19288 KB |
Output is correct |
44 |
Correct |
725 ms |
21840 KB |
Output is correct |
45 |
Correct |
706 ms |
21732 KB |
Output is correct |
46 |
Correct |
719 ms |
21840 KB |
Output is correct |
47 |
Correct |
582 ms |
19288 KB |
Output is correct |
48 |
Correct |
719 ms |
21840 KB |
Output is correct |
49 |
Correct |
678 ms |
21848 KB |
Output is correct |
50 |
Correct |
699 ms |
21840 KB |
Output is correct |
51 |
Correct |
321 ms |
12888 KB |
Output is correct |
52 |
Correct |
669 ms |
12888 KB |
Output is correct |
53 |
Correct |
604 ms |
12888 KB |
Output is correct |
54 |
Correct |
624 ms |
12888 KB |
Output is correct |
55 |
Correct |
763 ms |
24400 KB |
Output is correct |
56 |
Correct |
757 ms |
24676 KB |
Output is correct |
57 |
Correct |
797 ms |
24400 KB |
Output is correct |
58 |
Correct |
647 ms |
24404 KB |
Output is correct |
59 |
Correct |
757 ms |
36944 KB |
Output is correct |
60 |
Correct |
783 ms |
37092 KB |
Output is correct |
61 |
Correct |
422 ms |
12888 KB |
Output is correct |
62 |
Correct |
583 ms |
12888 KB |
Output is correct |
63 |
Correct |
615 ms |
12888 KB |
Output is correct |
64 |
Correct |
644 ms |
15192 KB |
Output is correct |
65 |
Correct |
671 ms |
15192 KB |
Output is correct |
66 |
Correct |
629 ms |
15192 KB |
Output is correct |
67 |
Correct |
644 ms |
15192 KB |
Output is correct |
68 |
Correct |
637 ms |
15188 KB |
Output is correct |
69 |
Correct |
651 ms |
14936 KB |
Output is correct |
70 |
Correct |
672 ms |
14936 KB |
Output is correct |
71 |
Correct |
538 ms |
13400 KB |
Output is correct |
72 |
Correct |
677 ms |
15188 KB |
Output is correct |
73 |
Correct |
645 ms |
14936 KB |
Output is correct |
74 |
Correct |
655 ms |
14936 KB |
Output is correct |
75 |
Correct |
640 ms |
14936 KB |
Output is correct |
76 |
Correct |
699 ms |
15704 KB |
Output is correct |
77 |
Correct |
630 ms |
15704 KB |
Output is correct |
78 |
Correct |
621 ms |
15704 KB |
Output is correct |
79 |
Correct |
666 ms |
13140 KB |
Output is correct |
80 |
Correct |
647 ms |
12888 KB |
Output is correct |
81 |
Correct |
623 ms |
12888 KB |
Output is correct |
82 |
Correct |
658 ms |
14936 KB |
Output is correct |
83 |
Correct |
309 ms |
12888 KB |
Output is correct |
84 |
Correct |
688 ms |
12888 KB |
Output is correct |
85 |
Correct |
665 ms |
12888 KB |
Output is correct |
86 |
Correct |
651 ms |
12888 KB |
Output is correct |
87 |
Correct |
2 ms |
12632 KB |
Output is correct |
88 |
Correct |
443 ms |
23744 KB |
Output is correct |
89 |
Correct |
731 ms |
21840 KB |
Output is correct |
90 |
Correct |
719 ms |
21840 KB |
Output is correct |
91 |
Correct |
746 ms |
24656 KB |
Output is correct |
92 |
Correct |
763 ms |
24656 KB |
Output is correct |
93 |
Correct |
763 ms |
24656 KB |
Output is correct |
94 |
Correct |
781 ms |
24544 KB |
Output is correct |
95 |
Correct |
755 ms |
24656 KB |
Output is correct |
96 |
Correct |
710 ms |
20168 KB |
Output is correct |
97 |
Correct |
704 ms |
20176 KB |
Output is correct |
98 |
Correct |
589 ms |
29784 KB |
Output is correct |
99 |
Correct |
767 ms |
24424 KB |
Output is correct |
100 |
Correct |
780 ms |
22096 KB |
Output is correct |
101 |
Correct |
739 ms |
21268 KB |
Output is correct |
102 |
Correct |
696 ms |
20048 KB |
Output is correct |
103 |
Correct |
731 ms |
36944 KB |
Output is correct |
104 |
Correct |
695 ms |
37596 KB |
Output is correct |
105 |
Correct |
678 ms |
37584 KB |
Output is correct |
106 |
Correct |
709 ms |
24400 KB |
Output is correct |
107 |
Correct |
737 ms |
20560 KB |
Output is correct |
108 |
Correct |
741 ms |
20560 KB |
Output is correct |
109 |
Correct |
734 ms |
20304 KB |
Output is correct |