#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 200005;
const ll mod = 1'000'002'022;
vector<int> adj[MAXN];
ll sbt[MAXN], lv[MAXN]; bool st[MAXN];
struct node{
int s, e, m; ll v0, v1; bool lazy;
node *l, *r;
node (int _s, int _e){
s = _s, e = _e, m = (s + e) >> 1, v0 = 0, v1 = 0, lazy = 0;
if (s == e) (st[s] ? v1 : v0) = lv[s];
else{
l = new node(s, m); r = new node(m + 1, e);
v0 = l->v0 + r->v0; v1 = l->v1 + r->v1;
}
}
void push(){
swap(v0, v1); lazy = !lazy;
}
void propo(){
if (s == e) return;
if (lazy){
l->push(); r->push();
lazy = 0;
}
}
void update(int x, int y){
if (x == s && y == e){
push(); return;
}
propo();
if (y <= m) l->update(x, y);
else if (x > m) r->update(x, y);
else{
l->update(x, m); r->update(m + 1, y);
}
propo();
v0 = l->v0 + r->v0; v1 = l->v1 + r->v1;
}
} *root;
void dfs(int x){
sbt[x] = max(1, (int)(adj[x].size()));
for (auto nn : adj[x]){
dfs(nn); sbt[x] = sbt[x] * sbt[nn] % mod;
}
}
void dfs2(int x, ll uv){
int asz = adj[x].size();
vector<ll> lp(asz + 2), rp(asz + 2);
lp[0] = 1; rp[asz + 1] = 1;
for (int i = 1; i <= asz; i++) lp[i] = lp[i - 1] * sbt[adj[x][i - 1]] % mod;
for (int i = asz; i >= 1; i--) rp[i] = rp[i + 1] * sbt[adj[x][i - 1]] % mod;
for (int i = 1; i <= asz; i++){
int nn = adj[x][i - 1]; dfs2(nn, uv * lp[i - 1] % mod * rp[i + 1] % mod);
}
lv[x] = uv;
}
void init(int N, int M, vector<int> P, vector<int> A) {
int tot = N + M;
for (int i = 1; i < tot; i++) adj[P[i]].push_back(i);
for (int i = N; i < tot; i++) st[i] = A[i - N];
dfs(0); dfs2(0, 1);
root = new node(N, tot - 1);
}
int count_ways(int L, int R) {
root->update(L, R);
return root->v1 % mod;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
6232 KB |
Output is correct |
2 |
Correct |
3 ms |
5152 KB |
Output is correct |
3 |
Correct |
3 ms |
5204 KB |
Output is correct |
4 |
Correct |
3 ms |
5208 KB |
Output is correct |
5 |
Correct |
3 ms |
5208 KB |
Output is correct |
6 |
Correct |
3 ms |
5208 KB |
Output is correct |
7 |
Correct |
2 ms |
6232 KB |
Output is correct |
8 |
Correct |
3 ms |
5208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4952 KB |
Output is correct |
2 |
Correct |
3 ms |
4952 KB |
Output is correct |
3 |
Correct |
3 ms |
5208 KB |
Output is correct |
4 |
Correct |
4 ms |
5208 KB |
Output is correct |
5 |
Correct |
3 ms |
5208 KB |
Output is correct |
6 |
Correct |
3 ms |
5208 KB |
Output is correct |
7 |
Correct |
5 ms |
5208 KB |
Output is correct |
8 |
Correct |
4 ms |
5208 KB |
Output is correct |
9 |
Correct |
3 ms |
5120 KB |
Output is correct |
10 |
Correct |
4 ms |
5464 KB |
Output is correct |
11 |
Correct |
3 ms |
6488 KB |
Output is correct |
12 |
Correct |
4 ms |
6232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
6232 KB |
Output is correct |
2 |
Correct |
3 ms |
5152 KB |
Output is correct |
3 |
Correct |
3 ms |
5204 KB |
Output is correct |
4 |
Correct |
3 ms |
5208 KB |
Output is correct |
5 |
Correct |
3 ms |
5208 KB |
Output is correct |
6 |
Correct |
3 ms |
5208 KB |
Output is correct |
7 |
Correct |
2 ms |
6232 KB |
Output is correct |
8 |
Correct |
3 ms |
5208 KB |
Output is correct |
9 |
Correct |
3 ms |
4952 KB |
Output is correct |
10 |
Correct |
3 ms |
4952 KB |
Output is correct |
11 |
Correct |
3 ms |
5208 KB |
Output is correct |
12 |
Correct |
4 ms |
5208 KB |
Output is correct |
13 |
Correct |
3 ms |
5208 KB |
Output is correct |
14 |
Correct |
3 ms |
5208 KB |
Output is correct |
15 |
Correct |
5 ms |
5208 KB |
Output is correct |
16 |
Correct |
4 ms |
5208 KB |
Output is correct |
17 |
Correct |
3 ms |
5120 KB |
Output is correct |
18 |
Correct |
4 ms |
5464 KB |
Output is correct |
19 |
Correct |
3 ms |
6488 KB |
Output is correct |
20 |
Correct |
4 ms |
6232 KB |
Output is correct |
21 |
Correct |
4 ms |
6232 KB |
Output is correct |
22 |
Correct |
3 ms |
5208 KB |
Output is correct |
23 |
Correct |
3 ms |
5208 KB |
Output is correct |
24 |
Correct |
4 ms |
5404 KB |
Output is correct |
25 |
Correct |
3 ms |
5208 KB |
Output is correct |
26 |
Correct |
3 ms |
5208 KB |
Output is correct |
27 |
Correct |
3 ms |
6232 KB |
Output is correct |
28 |
Correct |
3 ms |
5208 KB |
Output is correct |
29 |
Correct |
3 ms |
6232 KB |
Output is correct |
30 |
Correct |
3 ms |
6232 KB |
Output is correct |
31 |
Correct |
3 ms |
6488 KB |
Output is correct |
32 |
Correct |
3 ms |
6232 KB |
Output is correct |
33 |
Correct |
3 ms |
6232 KB |
Output is correct |
34 |
Correct |
3 ms |
6232 KB |
Output is correct |
35 |
Correct |
3 ms |
6232 KB |
Output is correct |
36 |
Correct |
3 ms |
6488 KB |
Output is correct |
37 |
Correct |
3 ms |
6488 KB |
Output is correct |
38 |
Correct |
3 ms |
6488 KB |
Output is correct |
39 |
Correct |
3 ms |
6232 KB |
Output is correct |
40 |
Correct |
4 ms |
6232 KB |
Output is correct |
41 |
Correct |
3 ms |
5208 KB |
Output is correct |
42 |
Correct |
3 ms |
5208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
448 ms |
13032 KB |
Output is correct |
2 |
Correct |
708 ms |
19544 KB |
Output is correct |
3 |
Correct |
642 ms |
19392 KB |
Output is correct |
4 |
Correct |
742 ms |
19476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
448 ms |
13032 KB |
Output is correct |
2 |
Correct |
708 ms |
19544 KB |
Output is correct |
3 |
Correct |
642 ms |
19392 KB |
Output is correct |
4 |
Correct |
742 ms |
19476 KB |
Output is correct |
5 |
Correct |
568 ms |
13144 KB |
Output is correct |
6 |
Correct |
660 ms |
19552 KB |
Output is correct |
7 |
Correct |
735 ms |
19532 KB |
Output is correct |
8 |
Correct |
559 ms |
19536 KB |
Output is correct |
9 |
Correct |
276 ms |
6532 KB |
Output is correct |
10 |
Correct |
626 ms |
5976 KB |
Output is correct |
11 |
Correct |
651 ms |
7000 KB |
Output is correct |
12 |
Correct |
547 ms |
7000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4952 KB |
Output is correct |
2 |
Correct |
3 ms |
4952 KB |
Output is correct |
3 |
Correct |
3 ms |
5208 KB |
Output is correct |
4 |
Correct |
4 ms |
5208 KB |
Output is correct |
5 |
Correct |
3 ms |
5208 KB |
Output is correct |
6 |
Correct |
3 ms |
5208 KB |
Output is correct |
7 |
Correct |
5 ms |
5208 KB |
Output is correct |
8 |
Correct |
4 ms |
5208 KB |
Output is correct |
9 |
Correct |
3 ms |
5120 KB |
Output is correct |
10 |
Correct |
4 ms |
5464 KB |
Output is correct |
11 |
Correct |
3 ms |
6488 KB |
Output is correct |
12 |
Correct |
4 ms |
6232 KB |
Output is correct |
13 |
Correct |
448 ms |
13032 KB |
Output is correct |
14 |
Correct |
708 ms |
19544 KB |
Output is correct |
15 |
Correct |
642 ms |
19392 KB |
Output is correct |
16 |
Correct |
742 ms |
19476 KB |
Output is correct |
17 |
Correct |
568 ms |
13144 KB |
Output is correct |
18 |
Correct |
660 ms |
19552 KB |
Output is correct |
19 |
Correct |
735 ms |
19532 KB |
Output is correct |
20 |
Correct |
559 ms |
19536 KB |
Output is correct |
21 |
Correct |
276 ms |
6532 KB |
Output is correct |
22 |
Correct |
626 ms |
5976 KB |
Output is correct |
23 |
Correct |
651 ms |
7000 KB |
Output is correct |
24 |
Correct |
547 ms |
7000 KB |
Output is correct |
25 |
Correct |
804 ms |
25824 KB |
Output is correct |
26 |
Correct |
802 ms |
26124 KB |
Output is correct |
27 |
Correct |
866 ms |
26332 KB |
Output is correct |
28 |
Correct |
532 ms |
26192 KB |
Output is correct |
29 |
Correct |
862 ms |
40384 KB |
Output is correct |
30 |
Correct |
569 ms |
40388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
6232 KB |
Output is correct |
2 |
Correct |
3 ms |
5152 KB |
Output is correct |
3 |
Correct |
3 ms |
5204 KB |
Output is correct |
4 |
Correct |
3 ms |
5208 KB |
Output is correct |
5 |
Correct |
3 ms |
5208 KB |
Output is correct |
6 |
Correct |
3 ms |
5208 KB |
Output is correct |
7 |
Correct |
2 ms |
6232 KB |
Output is correct |
8 |
Correct |
3 ms |
5208 KB |
Output is correct |
9 |
Correct |
3 ms |
4952 KB |
Output is correct |
10 |
Correct |
3 ms |
4952 KB |
Output is correct |
11 |
Correct |
3 ms |
5208 KB |
Output is correct |
12 |
Correct |
4 ms |
5208 KB |
Output is correct |
13 |
Correct |
3 ms |
5208 KB |
Output is correct |
14 |
Correct |
3 ms |
5208 KB |
Output is correct |
15 |
Correct |
5 ms |
5208 KB |
Output is correct |
16 |
Correct |
4 ms |
5208 KB |
Output is correct |
17 |
Correct |
3 ms |
5120 KB |
Output is correct |
18 |
Correct |
4 ms |
5464 KB |
Output is correct |
19 |
Correct |
3 ms |
6488 KB |
Output is correct |
20 |
Correct |
4 ms |
6232 KB |
Output is correct |
21 |
Correct |
4 ms |
6232 KB |
Output is correct |
22 |
Correct |
3 ms |
5208 KB |
Output is correct |
23 |
Correct |
3 ms |
5208 KB |
Output is correct |
24 |
Correct |
4 ms |
5404 KB |
Output is correct |
25 |
Correct |
3 ms |
5208 KB |
Output is correct |
26 |
Correct |
3 ms |
5208 KB |
Output is correct |
27 |
Correct |
3 ms |
6232 KB |
Output is correct |
28 |
Correct |
3 ms |
5208 KB |
Output is correct |
29 |
Correct |
3 ms |
6232 KB |
Output is correct |
30 |
Correct |
3 ms |
6232 KB |
Output is correct |
31 |
Correct |
3 ms |
6488 KB |
Output is correct |
32 |
Correct |
3 ms |
6232 KB |
Output is correct |
33 |
Correct |
3 ms |
6232 KB |
Output is correct |
34 |
Correct |
3 ms |
6232 KB |
Output is correct |
35 |
Correct |
3 ms |
6232 KB |
Output is correct |
36 |
Correct |
3 ms |
6488 KB |
Output is correct |
37 |
Correct |
3 ms |
6488 KB |
Output is correct |
38 |
Correct |
3 ms |
6488 KB |
Output is correct |
39 |
Correct |
3 ms |
6232 KB |
Output is correct |
40 |
Correct |
4 ms |
6232 KB |
Output is correct |
41 |
Correct |
3 ms |
5208 KB |
Output is correct |
42 |
Correct |
3 ms |
5208 KB |
Output is correct |
43 |
Correct |
431 ms |
6828 KB |
Output is correct |
44 |
Correct |
608 ms |
5720 KB |
Output is correct |
45 |
Correct |
579 ms |
6744 KB |
Output is correct |
46 |
Correct |
576 ms |
7256 KB |
Output is correct |
47 |
Correct |
572 ms |
7256 KB |
Output is correct |
48 |
Correct |
610 ms |
7256 KB |
Output is correct |
49 |
Correct |
589 ms |
5976 KB |
Output is correct |
50 |
Correct |
578 ms |
5976 KB |
Output is correct |
51 |
Correct |
591 ms |
5720 KB |
Output is correct |
52 |
Correct |
548 ms |
5720 KB |
Output is correct |
53 |
Correct |
546 ms |
6232 KB |
Output is correct |
54 |
Correct |
590 ms |
5976 KB |
Output is correct |
55 |
Correct |
610 ms |
5976 KB |
Output is correct |
56 |
Correct |
594 ms |
5976 KB |
Output is correct |
57 |
Correct |
642 ms |
5720 KB |
Output is correct |
58 |
Correct |
588 ms |
7768 KB |
Output is correct |
59 |
Correct |
609 ms |
8024 KB |
Output is correct |
60 |
Correct |
460 ms |
6744 KB |
Output is correct |
61 |
Correct |
544 ms |
6744 KB |
Output is correct |
62 |
Correct |
534 ms |
6744 KB |
Output is correct |
63 |
Correct |
606 ms |
6744 KB |
Output is correct |
64 |
Correct |
541 ms |
7000 KB |
Output is correct |
65 |
Correct |
324 ms |
5464 KB |
Output is correct |
66 |
Correct |
558 ms |
7000 KB |
Output is correct |
67 |
Correct |
561 ms |
7000 KB |
Output is correct |
68 |
Correct |
575 ms |
5976 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
6232 KB |
Output is correct |
2 |
Correct |
3 ms |
5152 KB |
Output is correct |
3 |
Correct |
3 ms |
5204 KB |
Output is correct |
4 |
Correct |
3 ms |
5208 KB |
Output is correct |
5 |
Correct |
3 ms |
5208 KB |
Output is correct |
6 |
Correct |
3 ms |
5208 KB |
Output is correct |
7 |
Correct |
2 ms |
6232 KB |
Output is correct |
8 |
Correct |
3 ms |
5208 KB |
Output is correct |
9 |
Correct |
3 ms |
4952 KB |
Output is correct |
10 |
Correct |
3 ms |
4952 KB |
Output is correct |
11 |
Correct |
3 ms |
5208 KB |
Output is correct |
12 |
Correct |
4 ms |
5208 KB |
Output is correct |
13 |
Correct |
3 ms |
5208 KB |
Output is correct |
14 |
Correct |
3 ms |
5208 KB |
Output is correct |
15 |
Correct |
5 ms |
5208 KB |
Output is correct |
16 |
Correct |
4 ms |
5208 KB |
Output is correct |
17 |
Correct |
3 ms |
5120 KB |
Output is correct |
18 |
Correct |
4 ms |
5464 KB |
Output is correct |
19 |
Correct |
3 ms |
6488 KB |
Output is correct |
20 |
Correct |
4 ms |
6232 KB |
Output is correct |
21 |
Correct |
4 ms |
6232 KB |
Output is correct |
22 |
Correct |
3 ms |
5208 KB |
Output is correct |
23 |
Correct |
3 ms |
5208 KB |
Output is correct |
24 |
Correct |
4 ms |
5404 KB |
Output is correct |
25 |
Correct |
3 ms |
5208 KB |
Output is correct |
26 |
Correct |
3 ms |
5208 KB |
Output is correct |
27 |
Correct |
3 ms |
6232 KB |
Output is correct |
28 |
Correct |
3 ms |
5208 KB |
Output is correct |
29 |
Correct |
3 ms |
6232 KB |
Output is correct |
30 |
Correct |
3 ms |
6232 KB |
Output is correct |
31 |
Correct |
3 ms |
6488 KB |
Output is correct |
32 |
Correct |
3 ms |
6232 KB |
Output is correct |
33 |
Correct |
3 ms |
6232 KB |
Output is correct |
34 |
Correct |
3 ms |
6232 KB |
Output is correct |
35 |
Correct |
3 ms |
6232 KB |
Output is correct |
36 |
Correct |
3 ms |
6488 KB |
Output is correct |
37 |
Correct |
3 ms |
6488 KB |
Output is correct |
38 |
Correct |
3 ms |
6488 KB |
Output is correct |
39 |
Correct |
3 ms |
6232 KB |
Output is correct |
40 |
Correct |
4 ms |
6232 KB |
Output is correct |
41 |
Correct |
3 ms |
5208 KB |
Output is correct |
42 |
Correct |
3 ms |
5208 KB |
Output is correct |
43 |
Correct |
448 ms |
13032 KB |
Output is correct |
44 |
Correct |
708 ms |
19544 KB |
Output is correct |
45 |
Correct |
642 ms |
19392 KB |
Output is correct |
46 |
Correct |
742 ms |
19476 KB |
Output is correct |
47 |
Correct |
568 ms |
13144 KB |
Output is correct |
48 |
Correct |
660 ms |
19552 KB |
Output is correct |
49 |
Correct |
735 ms |
19532 KB |
Output is correct |
50 |
Correct |
559 ms |
19536 KB |
Output is correct |
51 |
Correct |
276 ms |
6532 KB |
Output is correct |
52 |
Correct |
626 ms |
5976 KB |
Output is correct |
53 |
Correct |
651 ms |
7000 KB |
Output is correct |
54 |
Correct |
547 ms |
7000 KB |
Output is correct |
55 |
Correct |
804 ms |
25824 KB |
Output is correct |
56 |
Correct |
802 ms |
26124 KB |
Output is correct |
57 |
Correct |
866 ms |
26332 KB |
Output is correct |
58 |
Correct |
532 ms |
26192 KB |
Output is correct |
59 |
Correct |
862 ms |
40384 KB |
Output is correct |
60 |
Correct |
569 ms |
40388 KB |
Output is correct |
61 |
Correct |
431 ms |
6828 KB |
Output is correct |
62 |
Correct |
608 ms |
5720 KB |
Output is correct |
63 |
Correct |
579 ms |
6744 KB |
Output is correct |
64 |
Correct |
576 ms |
7256 KB |
Output is correct |
65 |
Correct |
572 ms |
7256 KB |
Output is correct |
66 |
Correct |
610 ms |
7256 KB |
Output is correct |
67 |
Correct |
589 ms |
5976 KB |
Output is correct |
68 |
Correct |
578 ms |
5976 KB |
Output is correct |
69 |
Correct |
591 ms |
5720 KB |
Output is correct |
70 |
Correct |
548 ms |
5720 KB |
Output is correct |
71 |
Correct |
546 ms |
6232 KB |
Output is correct |
72 |
Correct |
590 ms |
5976 KB |
Output is correct |
73 |
Correct |
610 ms |
5976 KB |
Output is correct |
74 |
Correct |
594 ms |
5976 KB |
Output is correct |
75 |
Correct |
642 ms |
5720 KB |
Output is correct |
76 |
Correct |
588 ms |
7768 KB |
Output is correct |
77 |
Correct |
609 ms |
8024 KB |
Output is correct |
78 |
Correct |
460 ms |
6744 KB |
Output is correct |
79 |
Correct |
544 ms |
6744 KB |
Output is correct |
80 |
Correct |
534 ms |
6744 KB |
Output is correct |
81 |
Correct |
606 ms |
6744 KB |
Output is correct |
82 |
Correct |
541 ms |
7000 KB |
Output is correct |
83 |
Correct |
324 ms |
5464 KB |
Output is correct |
84 |
Correct |
558 ms |
7000 KB |
Output is correct |
85 |
Correct |
561 ms |
7000 KB |
Output is correct |
86 |
Correct |
575 ms |
5976 KB |
Output is correct |
87 |
Correct |
3 ms |
6232 KB |
Output is correct |
88 |
Correct |
521 ms |
23280 KB |
Output is correct |
89 |
Correct |
691 ms |
17492 KB |
Output is correct |
90 |
Correct |
760 ms |
18356 KB |
Output is correct |
91 |
Correct |
750 ms |
26244 KB |
Output is correct |
92 |
Correct |
894 ms |
26336 KB |
Output is correct |
93 |
Correct |
816 ms |
26340 KB |
Output is correct |
94 |
Correct |
844 ms |
26448 KB |
Output is correct |
95 |
Correct |
658 ms |
26340 KB |
Output is correct |
96 |
Correct |
582 ms |
21948 KB |
Output is correct |
97 |
Correct |
767 ms |
21936 KB |
Output is correct |
98 |
Correct |
625 ms |
31724 KB |
Output is correct |
99 |
Correct |
784 ms |
26336 KB |
Output is correct |
100 |
Correct |
799 ms |
23804 KB |
Output is correct |
101 |
Correct |
823 ms |
23264 KB |
Output is correct |
102 |
Correct |
775 ms |
21920 KB |
Output is correct |
103 |
Correct |
809 ms |
40212 KB |
Output is correct |
104 |
Correct |
799 ms |
40876 KB |
Output is correct |
105 |
Correct |
682 ms |
40780 KB |
Output is correct |
106 |
Correct |
722 ms |
19536 KB |
Output is correct |
107 |
Correct |
730 ms |
18428 KB |
Output is correct |
108 |
Correct |
772 ms |
19748 KB |
Output is correct |
109 |
Correct |
817 ms |
22096 KB |
Output is correct |