#include "circuit.h"
#include "bits/stdc++.h"
using namespace std;
#ifndef EVAL
#include "stub.cpp"
#endif
#define ar array
typedef long long ll;
const int N = 1e5 + 5;
const int mod = 1'000'002'022;
int N_;
struct ST{
ar<int, 2> tree[N << 2];
int c[N << 2];
ST(){
memset(tree, 0, sizeof tree);
memset(c, 0, sizeof c);
}
void push(int x, int lx, int rx){
if(lx == rx) return;
if(c[x]){
swap(tree[x << 1][0], tree[x << 1][1]);
swap(tree[x << 1 | 1][0], tree[x << 1 | 1][1]);
c[x << 1] ^= 1, c[x << 1 | 1] ^= 1;
}
c[x] = 0;
}
void set(int i, int v, int lx, int rx, int x){
if(lx == rx){
tree[x][0] = v;
return;
}
push(x, lx, rx);
int m = (lx + rx) >> 1;
if(i <= m) set(i, v, lx, m, x << 1);
else set(i, v, m + 1, rx, x << 1 | 1);
tree[x][0] = (tree[x << 1][0] + tree[x << 1 | 1][0]) % mod;
tree[x][1] = (tree[x << 1][1] + tree[x << 1 | 1][1]) % mod;
}
void set(int i, int v){
set(i, v, 0, N, 1);
}
void togl(int l, int r, int lx, int rx, int x){
if(lx > r || rx < l) return;
if(lx >= l && rx <= r){
c[x] ^= 1;
swap(tree[x][0], tree[x][1]);
return;
}
int m = (lx + rx) >> 1;
push(x, lx, rx);
togl(l, r, lx, m, x << 1);
togl(l, r, m + 1, rx, x << 1 | 1);
tree[x][0] = (tree[x << 1][0] + tree[x << 1 | 1][0]) % mod;
tree[x][1] = (tree[x << 1][1] + tree[x << 1 | 1][1]) % mod;
}
void togl(int l, int r){
togl(l, r, 0, N, 1);
}
}tree;
//~ struct ST{
//~ int a[N], c[N];
//~ ST(){
//~ memset(a, 0, sizeof a);
//~ memset(c, 0, sizeof c);
//~ }
//~ void set(int i, int v){
//~ a[i] = v;
//~ }
//~ void togl(int l, int r){
//~ for(int i=l;i<=r;i++){
//~ c[i] ^= 1;
//~ }
//~ }
//~ int get(){
//~ int res = 0;
//~ for(int i=0;i<N;i++){
//~ if(c[i]){
//~ res = (res + a[i]) % mod;
//~ }
//~ }
//~ return res;
//~ }
//~ }tree;
void init(int n, int m, vector<int> p, vector<int> a) {
vector<vector<int>> edges(n + m);
for(int i=1;i<n+m;i++){
edges[p[i]].push_back(i);
}
vector<int> dp(n + m), up(n + m);
function<void(int)> dfs = [&](int u){
dp[u] = max(1, (int)edges[u].size());
for(auto x : edges[u]){
dfs(x);
dp[u] = dp[u] * 1ll * dp[x] % mod;
}
};
dfs(0);
//~ for(int i=0;i<n+m;i++){
//~ cout<<dp[i]<<" ";
//~ }
//~ cout<<"\n";
function<void(int)> re = [&](int u){
int pref = 1;
vector<int> suff(edges[u].size() + 1);
suff.back() = 1;
for(int i=(int)edges[u].size() - 1;~i;i--){
suff[i] = suff[i + 1] * 1ll * dp[edges[u][i]] % mod;
}
for(int i=0;i<(int)edges[u].size();i++){
up[edges[u][i]] = up[u] * 1ll * suff[i + 1] % mod * 1ll * pref % mod;
pref = pref * 1ll * dp[edges[u][i]] % mod;
re(edges[u][i]);
}
};
up[0] = 1;
re(0);
for(int i=n;i<n+m;i++){
tree.set(i - n, up[i]);
//~ if(a[i - n]) tree.togl(i - n, i - n);
}
for(int i=n;i<n+m;i++){
if(a[i - n]) tree.togl(i - n, i - n);
}
N_ = n;
}
int count_ways(int l, int r) {
l -= N_, r -= N_;
tree.togl(l, r);
//~ return tree.get();
return tree.tree[1][1];
//~ cout<<tree.tree[1]<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5068 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
4944 KB |
Output is correct |
4 |
Correct |
2 ms |
4944 KB |
Output is correct |
5 |
Correct |
4 ms |
4944 KB |
Output is correct |
6 |
Correct |
2 ms |
4944 KB |
Output is correct |
7 |
Correct |
2 ms |
4944 KB |
Output is correct |
8 |
Correct |
3 ms |
4944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
2 ms |
4944 KB |
Output is correct |
4 |
Correct |
2 ms |
4944 KB |
Output is correct |
5 |
Correct |
2 ms |
4944 KB |
Output is correct |
6 |
Correct |
3 ms |
5072 KB |
Output is correct |
7 |
Correct |
4 ms |
5016 KB |
Output is correct |
8 |
Correct |
3 ms |
5072 KB |
Output is correct |
9 |
Correct |
3 ms |
5072 KB |
Output is correct |
10 |
Correct |
3 ms |
5200 KB |
Output is correct |
11 |
Correct |
3 ms |
5236 KB |
Output is correct |
12 |
Correct |
3 ms |
5072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5068 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
4944 KB |
Output is correct |
4 |
Correct |
2 ms |
4944 KB |
Output is correct |
5 |
Correct |
4 ms |
4944 KB |
Output is correct |
6 |
Correct |
2 ms |
4944 KB |
Output is correct |
7 |
Correct |
2 ms |
4944 KB |
Output is correct |
8 |
Correct |
3 ms |
4944 KB |
Output is correct |
9 |
Correct |
3 ms |
4944 KB |
Output is correct |
10 |
Correct |
2 ms |
4944 KB |
Output is correct |
11 |
Correct |
2 ms |
4944 KB |
Output is correct |
12 |
Correct |
2 ms |
4944 KB |
Output is correct |
13 |
Correct |
2 ms |
4944 KB |
Output is correct |
14 |
Correct |
3 ms |
5072 KB |
Output is correct |
15 |
Correct |
4 ms |
5016 KB |
Output is correct |
16 |
Correct |
3 ms |
5072 KB |
Output is correct |
17 |
Correct |
3 ms |
5072 KB |
Output is correct |
18 |
Correct |
3 ms |
5200 KB |
Output is correct |
19 |
Correct |
3 ms |
5236 KB |
Output is correct |
20 |
Correct |
3 ms |
5072 KB |
Output is correct |
21 |
Correct |
3 ms |
5072 KB |
Output is correct |
22 |
Correct |
3 ms |
4944 KB |
Output is correct |
23 |
Correct |
4 ms |
4944 KB |
Output is correct |
24 |
Correct |
4 ms |
5072 KB |
Output is correct |
25 |
Correct |
3 ms |
5072 KB |
Output is correct |
26 |
Correct |
4 ms |
5072 KB |
Output is correct |
27 |
Correct |
3 ms |
5072 KB |
Output is correct |
28 |
Correct |
3 ms |
5072 KB |
Output is correct |
29 |
Correct |
3 ms |
4944 KB |
Output is correct |
30 |
Correct |
3 ms |
4944 KB |
Output is correct |
31 |
Correct |
2 ms |
5200 KB |
Output is correct |
32 |
Correct |
3 ms |
5072 KB |
Output is correct |
33 |
Correct |
3 ms |
5072 KB |
Output is correct |
34 |
Correct |
3 ms |
4944 KB |
Output is correct |
35 |
Correct |
3 ms |
4984 KB |
Output is correct |
36 |
Correct |
3 ms |
5240 KB |
Output is correct |
37 |
Correct |
3 ms |
5200 KB |
Output is correct |
38 |
Correct |
3 ms |
5200 KB |
Output is correct |
39 |
Correct |
3 ms |
5072 KB |
Output is correct |
40 |
Correct |
4 ms |
4944 KB |
Output is correct |
41 |
Correct |
3 ms |
4944 KB |
Output is correct |
42 |
Correct |
3 ms |
4944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
477 ms |
8860 KB |
Output is correct |
2 |
Correct |
685 ms |
12684 KB |
Output is correct |
3 |
Correct |
712 ms |
12680 KB |
Output is correct |
4 |
Correct |
558 ms |
12664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
477 ms |
8860 KB |
Output is correct |
2 |
Correct |
685 ms |
12684 KB |
Output is correct |
3 |
Correct |
712 ms |
12680 KB |
Output is correct |
4 |
Correct |
558 ms |
12664 KB |
Output is correct |
5 |
Correct |
589 ms |
8784 KB |
Output is correct |
6 |
Correct |
755 ms |
12664 KB |
Output is correct |
7 |
Correct |
568 ms |
12676 KB |
Output is correct |
8 |
Correct |
731 ms |
12616 KB |
Output is correct |
9 |
Correct |
330 ms |
5116 KB |
Output is correct |
10 |
Correct |
727 ms |
5376 KB |
Output is correct |
11 |
Correct |
688 ms |
5428 KB |
Output is correct |
12 |
Correct |
646 ms |
5380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
2 ms |
4944 KB |
Output is correct |
4 |
Correct |
2 ms |
4944 KB |
Output is correct |
5 |
Correct |
2 ms |
4944 KB |
Output is correct |
6 |
Correct |
3 ms |
5072 KB |
Output is correct |
7 |
Correct |
4 ms |
5016 KB |
Output is correct |
8 |
Correct |
3 ms |
5072 KB |
Output is correct |
9 |
Correct |
3 ms |
5072 KB |
Output is correct |
10 |
Correct |
3 ms |
5200 KB |
Output is correct |
11 |
Correct |
3 ms |
5236 KB |
Output is correct |
12 |
Correct |
3 ms |
5072 KB |
Output is correct |
13 |
Correct |
477 ms |
8860 KB |
Output is correct |
14 |
Correct |
685 ms |
12684 KB |
Output is correct |
15 |
Correct |
712 ms |
12680 KB |
Output is correct |
16 |
Correct |
558 ms |
12664 KB |
Output is correct |
17 |
Correct |
589 ms |
8784 KB |
Output is correct |
18 |
Correct |
755 ms |
12664 KB |
Output is correct |
19 |
Correct |
568 ms |
12676 KB |
Output is correct |
20 |
Correct |
731 ms |
12616 KB |
Output is correct |
21 |
Correct |
330 ms |
5116 KB |
Output is correct |
22 |
Correct |
727 ms |
5376 KB |
Output is correct |
23 |
Correct |
688 ms |
5428 KB |
Output is correct |
24 |
Correct |
646 ms |
5380 KB |
Output is correct |
25 |
Correct |
769 ms |
16524 KB |
Output is correct |
26 |
Correct |
806 ms |
16744 KB |
Output is correct |
27 |
Correct |
796 ms |
16744 KB |
Output is correct |
28 |
Correct |
682 ms |
16744 KB |
Output is correct |
29 |
Correct |
744 ms |
30792 KB |
Output is correct |
30 |
Correct |
749 ms |
30696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5068 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
4944 KB |
Output is correct |
4 |
Correct |
2 ms |
4944 KB |
Output is correct |
5 |
Correct |
4 ms |
4944 KB |
Output is correct |
6 |
Correct |
2 ms |
4944 KB |
Output is correct |
7 |
Correct |
2 ms |
4944 KB |
Output is correct |
8 |
Correct |
3 ms |
4944 KB |
Output is correct |
9 |
Correct |
3 ms |
4944 KB |
Output is correct |
10 |
Correct |
2 ms |
4944 KB |
Output is correct |
11 |
Correct |
2 ms |
4944 KB |
Output is correct |
12 |
Correct |
2 ms |
4944 KB |
Output is correct |
13 |
Correct |
2 ms |
4944 KB |
Output is correct |
14 |
Correct |
3 ms |
5072 KB |
Output is correct |
15 |
Correct |
4 ms |
5016 KB |
Output is correct |
16 |
Correct |
3 ms |
5072 KB |
Output is correct |
17 |
Correct |
3 ms |
5072 KB |
Output is correct |
18 |
Correct |
3 ms |
5200 KB |
Output is correct |
19 |
Correct |
3 ms |
5236 KB |
Output is correct |
20 |
Correct |
3 ms |
5072 KB |
Output is correct |
21 |
Correct |
3 ms |
5072 KB |
Output is correct |
22 |
Correct |
3 ms |
4944 KB |
Output is correct |
23 |
Correct |
4 ms |
4944 KB |
Output is correct |
24 |
Correct |
4 ms |
5072 KB |
Output is correct |
25 |
Correct |
3 ms |
5072 KB |
Output is correct |
26 |
Correct |
4 ms |
5072 KB |
Output is correct |
27 |
Correct |
3 ms |
5072 KB |
Output is correct |
28 |
Correct |
3 ms |
5072 KB |
Output is correct |
29 |
Correct |
3 ms |
4944 KB |
Output is correct |
30 |
Correct |
3 ms |
4944 KB |
Output is correct |
31 |
Correct |
2 ms |
5200 KB |
Output is correct |
32 |
Correct |
3 ms |
5072 KB |
Output is correct |
33 |
Correct |
3 ms |
5072 KB |
Output is correct |
34 |
Correct |
3 ms |
4944 KB |
Output is correct |
35 |
Correct |
3 ms |
4984 KB |
Output is correct |
36 |
Correct |
3 ms |
5240 KB |
Output is correct |
37 |
Correct |
3 ms |
5200 KB |
Output is correct |
38 |
Correct |
3 ms |
5200 KB |
Output is correct |
39 |
Correct |
3 ms |
5072 KB |
Output is correct |
40 |
Correct |
4 ms |
4944 KB |
Output is correct |
41 |
Correct |
3 ms |
4944 KB |
Output is correct |
42 |
Correct |
3 ms |
4944 KB |
Output is correct |
43 |
Correct |
422 ms |
5328 KB |
Output is correct |
44 |
Correct |
617 ms |
5376 KB |
Output is correct |
45 |
Correct |
665 ms |
5376 KB |
Output is correct |
46 |
Correct |
684 ms |
5496 KB |
Output is correct |
47 |
Correct |
577 ms |
5584 KB |
Output is correct |
48 |
Correct |
681 ms |
5504 KB |
Output is correct |
49 |
Correct |
673 ms |
5512 KB |
Output is correct |
50 |
Correct |
694 ms |
5584 KB |
Output is correct |
51 |
Correct |
591 ms |
5200 KB |
Output is correct |
52 |
Correct |
702 ms |
5240 KB |
Output is correct |
53 |
Correct |
507 ms |
6012 KB |
Output is correct |
54 |
Correct |
705 ms |
5508 KB |
Output is correct |
55 |
Correct |
646 ms |
5372 KB |
Output is correct |
56 |
Correct |
652 ms |
5248 KB |
Output is correct |
57 |
Correct |
645 ms |
5200 KB |
Output is correct |
58 |
Correct |
689 ms |
6224 KB |
Output is correct |
59 |
Correct |
630 ms |
6216 KB |
Output is correct |
60 |
Correct |
608 ms |
6268 KB |
Output is correct |
61 |
Correct |
622 ms |
5456 KB |
Output is correct |
62 |
Correct |
625 ms |
5248 KB |
Output is correct |
63 |
Correct |
634 ms |
5236 KB |
Output is correct |
64 |
Correct |
679 ms |
5240 KB |
Output is correct |
65 |
Correct |
327 ms |
5200 KB |
Output is correct |
66 |
Correct |
635 ms |
5456 KB |
Output is correct |
67 |
Correct |
566 ms |
5372 KB |
Output is correct |
68 |
Correct |
561 ms |
5376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5068 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
4944 KB |
Output is correct |
4 |
Correct |
2 ms |
4944 KB |
Output is correct |
5 |
Correct |
4 ms |
4944 KB |
Output is correct |
6 |
Correct |
2 ms |
4944 KB |
Output is correct |
7 |
Correct |
2 ms |
4944 KB |
Output is correct |
8 |
Correct |
3 ms |
4944 KB |
Output is correct |
9 |
Correct |
3 ms |
4944 KB |
Output is correct |
10 |
Correct |
2 ms |
4944 KB |
Output is correct |
11 |
Correct |
2 ms |
4944 KB |
Output is correct |
12 |
Correct |
2 ms |
4944 KB |
Output is correct |
13 |
Correct |
2 ms |
4944 KB |
Output is correct |
14 |
Correct |
3 ms |
5072 KB |
Output is correct |
15 |
Correct |
4 ms |
5016 KB |
Output is correct |
16 |
Correct |
3 ms |
5072 KB |
Output is correct |
17 |
Correct |
3 ms |
5072 KB |
Output is correct |
18 |
Correct |
3 ms |
5200 KB |
Output is correct |
19 |
Correct |
3 ms |
5236 KB |
Output is correct |
20 |
Correct |
3 ms |
5072 KB |
Output is correct |
21 |
Correct |
3 ms |
5072 KB |
Output is correct |
22 |
Correct |
3 ms |
4944 KB |
Output is correct |
23 |
Correct |
4 ms |
4944 KB |
Output is correct |
24 |
Correct |
4 ms |
5072 KB |
Output is correct |
25 |
Correct |
3 ms |
5072 KB |
Output is correct |
26 |
Correct |
4 ms |
5072 KB |
Output is correct |
27 |
Correct |
3 ms |
5072 KB |
Output is correct |
28 |
Correct |
3 ms |
5072 KB |
Output is correct |
29 |
Correct |
3 ms |
4944 KB |
Output is correct |
30 |
Correct |
3 ms |
4944 KB |
Output is correct |
31 |
Correct |
2 ms |
5200 KB |
Output is correct |
32 |
Correct |
3 ms |
5072 KB |
Output is correct |
33 |
Correct |
3 ms |
5072 KB |
Output is correct |
34 |
Correct |
3 ms |
4944 KB |
Output is correct |
35 |
Correct |
3 ms |
4984 KB |
Output is correct |
36 |
Correct |
3 ms |
5240 KB |
Output is correct |
37 |
Correct |
3 ms |
5200 KB |
Output is correct |
38 |
Correct |
3 ms |
5200 KB |
Output is correct |
39 |
Correct |
3 ms |
5072 KB |
Output is correct |
40 |
Correct |
4 ms |
4944 KB |
Output is correct |
41 |
Correct |
3 ms |
4944 KB |
Output is correct |
42 |
Correct |
3 ms |
4944 KB |
Output is correct |
43 |
Correct |
477 ms |
8860 KB |
Output is correct |
44 |
Correct |
685 ms |
12684 KB |
Output is correct |
45 |
Correct |
712 ms |
12680 KB |
Output is correct |
46 |
Correct |
558 ms |
12664 KB |
Output is correct |
47 |
Correct |
589 ms |
8784 KB |
Output is correct |
48 |
Correct |
755 ms |
12664 KB |
Output is correct |
49 |
Correct |
568 ms |
12676 KB |
Output is correct |
50 |
Correct |
731 ms |
12616 KB |
Output is correct |
51 |
Correct |
330 ms |
5116 KB |
Output is correct |
52 |
Correct |
727 ms |
5376 KB |
Output is correct |
53 |
Correct |
688 ms |
5428 KB |
Output is correct |
54 |
Correct |
646 ms |
5380 KB |
Output is correct |
55 |
Correct |
769 ms |
16524 KB |
Output is correct |
56 |
Correct |
806 ms |
16744 KB |
Output is correct |
57 |
Correct |
796 ms |
16744 KB |
Output is correct |
58 |
Correct |
682 ms |
16744 KB |
Output is correct |
59 |
Correct |
744 ms |
30792 KB |
Output is correct |
60 |
Correct |
749 ms |
30696 KB |
Output is correct |
61 |
Correct |
422 ms |
5328 KB |
Output is correct |
62 |
Correct |
617 ms |
5376 KB |
Output is correct |
63 |
Correct |
665 ms |
5376 KB |
Output is correct |
64 |
Correct |
684 ms |
5496 KB |
Output is correct |
65 |
Correct |
577 ms |
5584 KB |
Output is correct |
66 |
Correct |
681 ms |
5504 KB |
Output is correct |
67 |
Correct |
673 ms |
5512 KB |
Output is correct |
68 |
Correct |
694 ms |
5584 KB |
Output is correct |
69 |
Correct |
591 ms |
5200 KB |
Output is correct |
70 |
Correct |
702 ms |
5240 KB |
Output is correct |
71 |
Correct |
507 ms |
6012 KB |
Output is correct |
72 |
Correct |
705 ms |
5508 KB |
Output is correct |
73 |
Correct |
646 ms |
5372 KB |
Output is correct |
74 |
Correct |
652 ms |
5248 KB |
Output is correct |
75 |
Correct |
645 ms |
5200 KB |
Output is correct |
76 |
Correct |
689 ms |
6224 KB |
Output is correct |
77 |
Correct |
630 ms |
6216 KB |
Output is correct |
78 |
Correct |
608 ms |
6268 KB |
Output is correct |
79 |
Correct |
622 ms |
5456 KB |
Output is correct |
80 |
Correct |
625 ms |
5248 KB |
Output is correct |
81 |
Correct |
634 ms |
5236 KB |
Output is correct |
82 |
Correct |
679 ms |
5240 KB |
Output is correct |
83 |
Correct |
327 ms |
5200 KB |
Output is correct |
84 |
Correct |
635 ms |
5456 KB |
Output is correct |
85 |
Correct |
566 ms |
5372 KB |
Output is correct |
86 |
Correct |
561 ms |
5376 KB |
Output is correct |
87 |
Correct |
2 ms |
4944 KB |
Output is correct |
88 |
Correct |
515 ms |
15484 KB |
Output is correct |
89 |
Correct |
738 ms |
12840 KB |
Output is correct |
90 |
Correct |
817 ms |
12364 KB |
Output is correct |
91 |
Correct |
801 ms |
16852 KB |
Output is correct |
92 |
Correct |
792 ms |
16760 KB |
Output is correct |
93 |
Correct |
649 ms |
16856 KB |
Output is correct |
94 |
Correct |
713 ms |
16844 KB |
Output is correct |
95 |
Correct |
655 ms |
16760 KB |
Output is correct |
96 |
Correct |
694 ms |
10480 KB |
Output is correct |
97 |
Correct |
733 ms |
10496 KB |
Output is correct |
98 |
Correct |
548 ms |
26096 KB |
Output is correct |
99 |
Correct |
1039 ms |
16744 KB |
Output is correct |
100 |
Correct |
988 ms |
13208 KB |
Output is correct |
101 |
Correct |
582 ms |
11896 KB |
Output is correct |
102 |
Correct |
725 ms |
10200 KB |
Output is correct |
103 |
Correct |
936 ms |
30828 KB |
Output is correct |
104 |
Correct |
928 ms |
31520 KB |
Output is correct |
105 |
Correct |
678 ms |
31596 KB |
Output is correct |
106 |
Correct |
668 ms |
15348 KB |
Output is correct |
107 |
Correct |
577 ms |
11032 KB |
Output is correct |
108 |
Correct |
698 ms |
10904 KB |
Output is correct |
109 |
Correct |
683 ms |
10232 KB |
Output is correct |