#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 200005;
const int MOD = 1e9 + 2022;
int binpow(int n, int k){
int res = 1;
while (k > 0){
if (k & 1) res = 1LL * res * n % MOD;
n = 1LL * n * n % MOD;
k >>= 1;
}
return res;
}
int N, M;
vector<int> A;
int contribution[MaxN];
struct node{
int sum;
int sum2;
bool flag;
node(){
sum = sum2 = 0;
flag = false;
};
};
node tree[4 * MaxN];
void flip(int v){
swap(tree[v].sum, tree[v].sum2);
tree[v].flag ^= 1;
}
void push(int v, int tl, int tr){
if (tl == tr || !tree[v].flag) return;
flip(v << 1);
flip(v << 1 | 1);
tree[v].flag = false;
}
void build(int v, int tl, int tr){
if (tl == tr){
tree[v].sum = A[tl - N] * contribution[tl];
tree[v].sum2 = (!A[tl - N]) * contribution[tl];
return;
}
int tm = (tl + tr) >> 1;
build(v << 1, tl, tm);
build(v << 1 | 1, tm + 1, tr);
tree[v].sum = (tree[v << 1].sum + tree[v << 1 | 1].sum) % MOD;
tree[v].sum2 = (tree[v << 1].sum2 + tree[v << 1 | 1].sum2) % MOD;
}
void update(int v, int tl, int tr, int l, int r){
push(v, tl, tr);
if (l <= tl && tr <= r){
flip(v);
return;
}
if (tl > r || tr < l) return;
int tm = (tl + tr) >> 1;
update(v << 1, tl, tm, l, r);
update(v << 1 | 1, tm + 1, tr, l, r);
tree[v].sum = (tree[v << 1].sum + tree[v << 1 | 1].sum) % MOD;
tree[v].sum2 = (tree[v << 1].sum2 + tree[v << 1 | 1].sum2) % MOD;
}
void update(int l, int r){
update(1, N, N + M - 1, l, r);
}
int get(){
return tree[1].sum;
}
vector<int> g[MaxN];
int dep[MaxN];
void dfs(int v, int p, map<int, int> mp){
int sz = (int) g[v].size();
if (sz == 0){
int &res = contribution[v];
res = 1;
for (auto [d, cnt] : mp){
res = 1LL * res * binpow(d, cnt) % MOD;
}
} else {
mp[sz]--;
}
for (int u : g[v]){
if (u != p){
dfs(u, v, mp);
}
}
}
void init(int _N, int _M, vector<int> P, vector<int> _A) {
N = _N, M = _M, A = _A;
for (int i = 1; i < N + M; i++){
g[P[i]].push_back(i);
}
map<int, int> mp;
for (int i = 0; i < N; i++){
mp[(int) g[i].size()]++;
}
dfs(0, -1, mp);
build(1, N, N + M - 1);
}
int count_ways(int L, int R) {
update(L, R);
return get();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14288 KB |
Output is correct |
2 |
Correct |
7 ms |
14288 KB |
Output is correct |
3 |
Correct |
6 ms |
14328 KB |
Output is correct |
4 |
Correct |
6 ms |
14416 KB |
Output is correct |
5 |
Correct |
6 ms |
14416 KB |
Output is correct |
6 |
Correct |
7 ms |
14416 KB |
Output is correct |
7 |
Correct |
6 ms |
14416 KB |
Output is correct |
8 |
Correct |
7 ms |
14416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
14288 KB |
Output is correct |
2 |
Correct |
6 ms |
14416 KB |
Output is correct |
3 |
Correct |
6 ms |
14416 KB |
Output is correct |
4 |
Correct |
6 ms |
14416 KB |
Output is correct |
5 |
Correct |
7 ms |
14416 KB |
Output is correct |
6 |
Correct |
7 ms |
14416 KB |
Output is correct |
7 |
Correct |
7 ms |
14416 KB |
Output is correct |
8 |
Correct |
7 ms |
14416 KB |
Output is correct |
9 |
Correct |
7 ms |
14416 KB |
Output is correct |
10 |
Correct |
7 ms |
14544 KB |
Output is correct |
11 |
Correct |
7 ms |
14544 KB |
Output is correct |
12 |
Correct |
6 ms |
14416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14288 KB |
Output is correct |
2 |
Correct |
7 ms |
14288 KB |
Output is correct |
3 |
Correct |
6 ms |
14328 KB |
Output is correct |
4 |
Correct |
6 ms |
14416 KB |
Output is correct |
5 |
Correct |
6 ms |
14416 KB |
Output is correct |
6 |
Correct |
7 ms |
14416 KB |
Output is correct |
7 |
Correct |
6 ms |
14416 KB |
Output is correct |
8 |
Correct |
7 ms |
14416 KB |
Output is correct |
9 |
Correct |
6 ms |
14288 KB |
Output is correct |
10 |
Correct |
6 ms |
14416 KB |
Output is correct |
11 |
Correct |
6 ms |
14416 KB |
Output is correct |
12 |
Correct |
6 ms |
14416 KB |
Output is correct |
13 |
Correct |
7 ms |
14416 KB |
Output is correct |
14 |
Correct |
7 ms |
14416 KB |
Output is correct |
15 |
Correct |
7 ms |
14416 KB |
Output is correct |
16 |
Correct |
7 ms |
14416 KB |
Output is correct |
17 |
Correct |
7 ms |
14416 KB |
Output is correct |
18 |
Correct |
7 ms |
14544 KB |
Output is correct |
19 |
Correct |
7 ms |
14544 KB |
Output is correct |
20 |
Correct |
6 ms |
14416 KB |
Output is correct |
21 |
Correct |
7 ms |
14452 KB |
Output is correct |
22 |
Correct |
6 ms |
14416 KB |
Output is correct |
23 |
Correct |
6 ms |
14416 KB |
Output is correct |
24 |
Correct |
7 ms |
14416 KB |
Output is correct |
25 |
Correct |
7 ms |
14396 KB |
Output is correct |
26 |
Correct |
7 ms |
14416 KB |
Output is correct |
27 |
Correct |
8 ms |
14404 KB |
Output is correct |
28 |
Correct |
8 ms |
14416 KB |
Output is correct |
29 |
Correct |
6 ms |
14416 KB |
Output is correct |
30 |
Correct |
7 ms |
14348 KB |
Output is correct |
31 |
Correct |
7 ms |
14552 KB |
Output is correct |
32 |
Correct |
7 ms |
14416 KB |
Output is correct |
33 |
Correct |
7 ms |
14416 KB |
Output is correct |
34 |
Correct |
7 ms |
14368 KB |
Output is correct |
35 |
Correct |
6 ms |
14416 KB |
Output is correct |
36 |
Correct |
7 ms |
14664 KB |
Output is correct |
37 |
Correct |
7 ms |
14624 KB |
Output is correct |
38 |
Correct |
7 ms |
14672 KB |
Output is correct |
39 |
Correct |
7 ms |
14416 KB |
Output is correct |
40 |
Correct |
7 ms |
14380 KB |
Output is correct |
41 |
Correct |
7 ms |
14416 KB |
Output is correct |
42 |
Correct |
7 ms |
14416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
439 ms |
16464 KB |
Output is correct |
2 |
Correct |
712 ms |
18444 KB |
Output is correct |
3 |
Correct |
839 ms |
18500 KB |
Output is correct |
4 |
Correct |
641 ms |
18488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
439 ms |
16464 KB |
Output is correct |
2 |
Correct |
712 ms |
18444 KB |
Output is correct |
3 |
Correct |
839 ms |
18500 KB |
Output is correct |
4 |
Correct |
641 ms |
18488 KB |
Output is correct |
5 |
Correct |
653 ms |
16460 KB |
Output is correct |
6 |
Correct |
726 ms |
18496 KB |
Output is correct |
7 |
Correct |
880 ms |
18516 KB |
Output is correct |
8 |
Correct |
710 ms |
18472 KB |
Output is correct |
9 |
Correct |
386 ms |
14416 KB |
Output is correct |
10 |
Correct |
629 ms |
14544 KB |
Output is correct |
11 |
Correct |
651 ms |
14544 KB |
Output is correct |
12 |
Correct |
607 ms |
14560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
14288 KB |
Output is correct |
2 |
Correct |
6 ms |
14416 KB |
Output is correct |
3 |
Correct |
6 ms |
14416 KB |
Output is correct |
4 |
Correct |
6 ms |
14416 KB |
Output is correct |
5 |
Correct |
7 ms |
14416 KB |
Output is correct |
6 |
Correct |
7 ms |
14416 KB |
Output is correct |
7 |
Correct |
7 ms |
14416 KB |
Output is correct |
8 |
Correct |
7 ms |
14416 KB |
Output is correct |
9 |
Correct |
7 ms |
14416 KB |
Output is correct |
10 |
Correct |
7 ms |
14544 KB |
Output is correct |
11 |
Correct |
7 ms |
14544 KB |
Output is correct |
12 |
Correct |
6 ms |
14416 KB |
Output is correct |
13 |
Correct |
439 ms |
16464 KB |
Output is correct |
14 |
Correct |
712 ms |
18444 KB |
Output is correct |
15 |
Correct |
839 ms |
18500 KB |
Output is correct |
16 |
Correct |
641 ms |
18488 KB |
Output is correct |
17 |
Correct |
653 ms |
16460 KB |
Output is correct |
18 |
Correct |
726 ms |
18496 KB |
Output is correct |
19 |
Correct |
880 ms |
18516 KB |
Output is correct |
20 |
Correct |
710 ms |
18472 KB |
Output is correct |
21 |
Correct |
386 ms |
14416 KB |
Output is correct |
22 |
Correct |
629 ms |
14544 KB |
Output is correct |
23 |
Correct |
651 ms |
14544 KB |
Output is correct |
24 |
Correct |
607 ms |
14560 KB |
Output is correct |
25 |
Correct |
882 ms |
20552 KB |
Output is correct |
26 |
Correct |
743 ms |
20668 KB |
Output is correct |
27 |
Correct |
903 ms |
20660 KB |
Output is correct |
28 |
Correct |
696 ms |
20660 KB |
Output is correct |
29 |
Correct |
795 ms |
39508 KB |
Output is correct |
30 |
Correct |
777 ms |
39348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14288 KB |
Output is correct |
2 |
Correct |
7 ms |
14288 KB |
Output is correct |
3 |
Correct |
6 ms |
14328 KB |
Output is correct |
4 |
Correct |
6 ms |
14416 KB |
Output is correct |
5 |
Correct |
6 ms |
14416 KB |
Output is correct |
6 |
Correct |
7 ms |
14416 KB |
Output is correct |
7 |
Correct |
6 ms |
14416 KB |
Output is correct |
8 |
Correct |
7 ms |
14416 KB |
Output is correct |
9 |
Correct |
6 ms |
14288 KB |
Output is correct |
10 |
Correct |
6 ms |
14416 KB |
Output is correct |
11 |
Correct |
6 ms |
14416 KB |
Output is correct |
12 |
Correct |
6 ms |
14416 KB |
Output is correct |
13 |
Correct |
7 ms |
14416 KB |
Output is correct |
14 |
Correct |
7 ms |
14416 KB |
Output is correct |
15 |
Correct |
7 ms |
14416 KB |
Output is correct |
16 |
Correct |
7 ms |
14416 KB |
Output is correct |
17 |
Correct |
7 ms |
14416 KB |
Output is correct |
18 |
Correct |
7 ms |
14544 KB |
Output is correct |
19 |
Correct |
7 ms |
14544 KB |
Output is correct |
20 |
Correct |
6 ms |
14416 KB |
Output is correct |
21 |
Correct |
7 ms |
14452 KB |
Output is correct |
22 |
Correct |
6 ms |
14416 KB |
Output is correct |
23 |
Correct |
6 ms |
14416 KB |
Output is correct |
24 |
Correct |
7 ms |
14416 KB |
Output is correct |
25 |
Correct |
7 ms |
14396 KB |
Output is correct |
26 |
Correct |
7 ms |
14416 KB |
Output is correct |
27 |
Correct |
8 ms |
14404 KB |
Output is correct |
28 |
Correct |
8 ms |
14416 KB |
Output is correct |
29 |
Correct |
6 ms |
14416 KB |
Output is correct |
30 |
Correct |
7 ms |
14348 KB |
Output is correct |
31 |
Correct |
7 ms |
14552 KB |
Output is correct |
32 |
Correct |
7 ms |
14416 KB |
Output is correct |
33 |
Correct |
7 ms |
14416 KB |
Output is correct |
34 |
Correct |
7 ms |
14368 KB |
Output is correct |
35 |
Correct |
6 ms |
14416 KB |
Output is correct |
36 |
Correct |
7 ms |
14664 KB |
Output is correct |
37 |
Correct |
7 ms |
14624 KB |
Output is correct |
38 |
Correct |
7 ms |
14672 KB |
Output is correct |
39 |
Correct |
7 ms |
14416 KB |
Output is correct |
40 |
Correct |
7 ms |
14380 KB |
Output is correct |
41 |
Correct |
7 ms |
14416 KB |
Output is correct |
42 |
Correct |
7 ms |
14416 KB |
Output is correct |
43 |
Correct |
529 ms |
14544 KB |
Output is correct |
44 |
Correct |
623 ms |
14544 KB |
Output is correct |
45 |
Correct |
669 ms |
14544 KB |
Output is correct |
46 |
Correct |
707 ms |
14692 KB |
Output is correct |
47 |
Correct |
694 ms |
14672 KB |
Output is correct |
48 |
Correct |
727 ms |
14672 KB |
Output is correct |
49 |
Correct |
670 ms |
14732 KB |
Output is correct |
50 |
Correct |
827 ms |
14672 KB |
Output is correct |
51 |
Correct |
658 ms |
14544 KB |
Output is correct |
52 |
Correct |
797 ms |
14544 KB |
Output is correct |
53 |
Correct |
631 ms |
15440 KB |
Output is correct |
54 |
Correct |
824 ms |
14672 KB |
Output is correct |
55 |
Correct |
848 ms |
14544 KB |
Output is correct |
56 |
Correct |
726 ms |
14544 KB |
Output is correct |
57 |
Correct |
721 ms |
14416 KB |
Output is correct |
58 |
Correct |
595 ms |
15824 KB |
Output is correct |
59 |
Correct |
623 ms |
15824 KB |
Output is correct |
60 |
Correct |
743 ms |
15824 KB |
Output is correct |
61 |
Correct |
641 ms |
14928 KB |
Output is correct |
62 |
Correct |
830 ms |
14544 KB |
Output is correct |
63 |
Correct |
745 ms |
14544 KB |
Output is correct |
64 |
Correct |
639 ms |
14620 KB |
Output is correct |
65 |
Correct |
310 ms |
14504 KB |
Output is correct |
66 |
Correct |
649 ms |
14544 KB |
Output is correct |
67 |
Correct |
682 ms |
14548 KB |
Output is correct |
68 |
Correct |
549 ms |
14544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14288 KB |
Output is correct |
2 |
Correct |
7 ms |
14288 KB |
Output is correct |
3 |
Correct |
6 ms |
14328 KB |
Output is correct |
4 |
Correct |
6 ms |
14416 KB |
Output is correct |
5 |
Correct |
6 ms |
14416 KB |
Output is correct |
6 |
Correct |
7 ms |
14416 KB |
Output is correct |
7 |
Correct |
6 ms |
14416 KB |
Output is correct |
8 |
Correct |
7 ms |
14416 KB |
Output is correct |
9 |
Correct |
6 ms |
14288 KB |
Output is correct |
10 |
Correct |
6 ms |
14416 KB |
Output is correct |
11 |
Correct |
6 ms |
14416 KB |
Output is correct |
12 |
Correct |
6 ms |
14416 KB |
Output is correct |
13 |
Correct |
7 ms |
14416 KB |
Output is correct |
14 |
Correct |
7 ms |
14416 KB |
Output is correct |
15 |
Correct |
7 ms |
14416 KB |
Output is correct |
16 |
Correct |
7 ms |
14416 KB |
Output is correct |
17 |
Correct |
7 ms |
14416 KB |
Output is correct |
18 |
Correct |
7 ms |
14544 KB |
Output is correct |
19 |
Correct |
7 ms |
14544 KB |
Output is correct |
20 |
Correct |
6 ms |
14416 KB |
Output is correct |
21 |
Correct |
7 ms |
14452 KB |
Output is correct |
22 |
Correct |
6 ms |
14416 KB |
Output is correct |
23 |
Correct |
6 ms |
14416 KB |
Output is correct |
24 |
Correct |
7 ms |
14416 KB |
Output is correct |
25 |
Correct |
7 ms |
14396 KB |
Output is correct |
26 |
Correct |
7 ms |
14416 KB |
Output is correct |
27 |
Correct |
8 ms |
14404 KB |
Output is correct |
28 |
Correct |
8 ms |
14416 KB |
Output is correct |
29 |
Correct |
6 ms |
14416 KB |
Output is correct |
30 |
Correct |
7 ms |
14348 KB |
Output is correct |
31 |
Correct |
7 ms |
14552 KB |
Output is correct |
32 |
Correct |
7 ms |
14416 KB |
Output is correct |
33 |
Correct |
7 ms |
14416 KB |
Output is correct |
34 |
Correct |
7 ms |
14368 KB |
Output is correct |
35 |
Correct |
6 ms |
14416 KB |
Output is correct |
36 |
Correct |
7 ms |
14664 KB |
Output is correct |
37 |
Correct |
7 ms |
14624 KB |
Output is correct |
38 |
Correct |
7 ms |
14672 KB |
Output is correct |
39 |
Correct |
7 ms |
14416 KB |
Output is correct |
40 |
Correct |
7 ms |
14380 KB |
Output is correct |
41 |
Correct |
7 ms |
14416 KB |
Output is correct |
42 |
Correct |
7 ms |
14416 KB |
Output is correct |
43 |
Correct |
439 ms |
16464 KB |
Output is correct |
44 |
Correct |
712 ms |
18444 KB |
Output is correct |
45 |
Correct |
839 ms |
18500 KB |
Output is correct |
46 |
Correct |
641 ms |
18488 KB |
Output is correct |
47 |
Correct |
653 ms |
16460 KB |
Output is correct |
48 |
Correct |
726 ms |
18496 KB |
Output is correct |
49 |
Correct |
880 ms |
18516 KB |
Output is correct |
50 |
Correct |
710 ms |
18472 KB |
Output is correct |
51 |
Correct |
386 ms |
14416 KB |
Output is correct |
52 |
Correct |
629 ms |
14544 KB |
Output is correct |
53 |
Correct |
651 ms |
14544 KB |
Output is correct |
54 |
Correct |
607 ms |
14560 KB |
Output is correct |
55 |
Correct |
882 ms |
20552 KB |
Output is correct |
56 |
Correct |
743 ms |
20668 KB |
Output is correct |
57 |
Correct |
903 ms |
20660 KB |
Output is correct |
58 |
Correct |
696 ms |
20660 KB |
Output is correct |
59 |
Correct |
795 ms |
39508 KB |
Output is correct |
60 |
Correct |
777 ms |
39348 KB |
Output is correct |
61 |
Correct |
529 ms |
14544 KB |
Output is correct |
62 |
Correct |
623 ms |
14544 KB |
Output is correct |
63 |
Correct |
669 ms |
14544 KB |
Output is correct |
64 |
Correct |
707 ms |
14692 KB |
Output is correct |
65 |
Correct |
694 ms |
14672 KB |
Output is correct |
66 |
Correct |
727 ms |
14672 KB |
Output is correct |
67 |
Correct |
670 ms |
14732 KB |
Output is correct |
68 |
Correct |
827 ms |
14672 KB |
Output is correct |
69 |
Correct |
658 ms |
14544 KB |
Output is correct |
70 |
Correct |
797 ms |
14544 KB |
Output is correct |
71 |
Correct |
631 ms |
15440 KB |
Output is correct |
72 |
Correct |
824 ms |
14672 KB |
Output is correct |
73 |
Correct |
848 ms |
14544 KB |
Output is correct |
74 |
Correct |
726 ms |
14544 KB |
Output is correct |
75 |
Correct |
721 ms |
14416 KB |
Output is correct |
76 |
Correct |
595 ms |
15824 KB |
Output is correct |
77 |
Correct |
623 ms |
15824 KB |
Output is correct |
78 |
Correct |
743 ms |
15824 KB |
Output is correct |
79 |
Correct |
641 ms |
14928 KB |
Output is correct |
80 |
Correct |
830 ms |
14544 KB |
Output is correct |
81 |
Correct |
745 ms |
14544 KB |
Output is correct |
82 |
Correct |
639 ms |
14620 KB |
Output is correct |
83 |
Correct |
310 ms |
14504 KB |
Output is correct |
84 |
Correct |
649 ms |
14544 KB |
Output is correct |
85 |
Correct |
682 ms |
14548 KB |
Output is correct |
86 |
Correct |
549 ms |
14544 KB |
Output is correct |
87 |
Correct |
6 ms |
14288 KB |
Output is correct |
88 |
Correct |
613 ms |
20096 KB |
Output is correct |
89 |
Correct |
742 ms |
18632 KB |
Output is correct |
90 |
Correct |
695 ms |
18404 KB |
Output is correct |
91 |
Correct |
785 ms |
20792 KB |
Output is correct |
92 |
Correct |
797 ms |
20808 KB |
Output is correct |
93 |
Correct |
1103 ms |
20796 KB |
Output is correct |
94 |
Correct |
1027 ms |
20804 KB |
Output is correct |
95 |
Correct |
845 ms |
20796 KB |
Output is correct |
96 |
Correct |
719 ms |
17228 KB |
Output is correct |
97 |
Correct |
867 ms |
17196 KB |
Output is correct |
98 |
Correct |
569 ms |
36996 KB |
Output is correct |
99 |
Correct |
870 ms |
20564 KB |
Output is correct |
100 |
Correct |
847 ms |
18616 KB |
Output is correct |
101 |
Correct |
789 ms |
18232 KB |
Output is correct |
102 |
Correct |
692 ms |
17236 KB |
Output is correct |
103 |
Correct |
898 ms |
44108 KB |
Output is correct |
104 |
Correct |
838 ms |
44504 KB |
Output is correct |
105 |
Correct |
733 ms |
44536 KB |
Output is correct |
106 |
Correct |
757 ms |
28464 KB |
Output is correct |
107 |
Correct |
778 ms |
17596 KB |
Output is correct |
108 |
Correct |
743 ms |
17460 KB |
Output is correct |
109 |
Correct |
1869 ms |
17708 KB |
Output is correct |