#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 100005;
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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2900 KB |
Output is correct |
2 |
Correct |
2 ms |
2648 KB |
Output is correct |
3 |
Correct |
2 ms |
2904 KB |
Output is correct |
4 |
Correct |
3 ms |
2904 KB |
Output is correct |
5 |
Correct |
2 ms |
2904 KB |
Output is correct |
6 |
Correct |
2 ms |
4184 KB |
Output is correct |
7 |
Correct |
2 ms |
2904 KB |
Output is correct |
8 |
Correct |
2 ms |
2904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4184 KB |
Output is correct |
2 |
Correct |
3 ms |
4184 KB |
Output is correct |
3 |
Correct |
2 ms |
4184 KB |
Output is correct |
4 |
Correct |
2 ms |
2648 KB |
Output is correct |
5 |
Correct |
2 ms |
2648 KB |
Output is correct |
6 |
Correct |
2 ms |
2904 KB |
Output is correct |
7 |
Correct |
3 ms |
2904 KB |
Output is correct |
8 |
Correct |
2 ms |
2904 KB |
Output is correct |
9 |
Correct |
4 ms |
2908 KB |
Output is correct |
10 |
Correct |
2 ms |
2904 KB |
Output is correct |
11 |
Correct |
2 ms |
2904 KB |
Output is correct |
12 |
Correct |
3 ms |
2904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2900 KB |
Output is correct |
2 |
Correct |
2 ms |
2648 KB |
Output is correct |
3 |
Correct |
2 ms |
2904 KB |
Output is correct |
4 |
Correct |
3 ms |
2904 KB |
Output is correct |
5 |
Correct |
2 ms |
2904 KB |
Output is correct |
6 |
Correct |
2 ms |
4184 KB |
Output is correct |
7 |
Correct |
2 ms |
2904 KB |
Output is correct |
8 |
Correct |
2 ms |
2904 KB |
Output is correct |
9 |
Correct |
2 ms |
4184 KB |
Output is correct |
10 |
Correct |
3 ms |
4184 KB |
Output is correct |
11 |
Correct |
2 ms |
4184 KB |
Output is correct |
12 |
Correct |
2 ms |
2648 KB |
Output is correct |
13 |
Correct |
2 ms |
2648 KB |
Output is correct |
14 |
Correct |
2 ms |
2904 KB |
Output is correct |
15 |
Correct |
3 ms |
2904 KB |
Output is correct |
16 |
Correct |
2 ms |
2904 KB |
Output is correct |
17 |
Correct |
4 ms |
2908 KB |
Output is correct |
18 |
Correct |
2 ms |
2904 KB |
Output is correct |
19 |
Correct |
2 ms |
2904 KB |
Output is correct |
20 |
Correct |
3 ms |
2904 KB |
Output is correct |
21 |
Correct |
2 ms |
4440 KB |
Output is correct |
22 |
Correct |
2 ms |
4184 KB |
Output is correct |
23 |
Correct |
2 ms |
4184 KB |
Output is correct |
24 |
Correct |
3 ms |
4440 KB |
Output is correct |
25 |
Correct |
3 ms |
4440 KB |
Output is correct |
26 |
Correct |
3 ms |
2904 KB |
Output is correct |
27 |
Correct |
2 ms |
2904 KB |
Output is correct |
28 |
Correct |
2 ms |
2904 KB |
Output is correct |
29 |
Correct |
2 ms |
2904 KB |
Output is correct |
30 |
Correct |
2 ms |
2904 KB |
Output is correct |
31 |
Correct |
2 ms |
2812 KB |
Output is correct |
32 |
Correct |
2 ms |
2904 KB |
Output is correct |
33 |
Correct |
2 ms |
4440 KB |
Output is correct |
34 |
Correct |
3 ms |
2904 KB |
Output is correct |
35 |
Correct |
3 ms |
2912 KB |
Output is correct |
36 |
Correct |
3 ms |
4440 KB |
Output is correct |
37 |
Correct |
4 ms |
4440 KB |
Output is correct |
38 |
Correct |
2 ms |
2992 KB |
Output is correct |
39 |
Correct |
2 ms |
2904 KB |
Output is correct |
40 |
Correct |
2 ms |
3156 KB |
Output is correct |
41 |
Correct |
2 ms |
4184 KB |
Output is correct |
42 |
Correct |
2 ms |
2904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
452 ms |
9560 KB |
Output is correct |
2 |
Runtime error |
31 ms |
15536 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
452 ms |
9560 KB |
Output is correct |
2 |
Runtime error |
31 ms |
15536 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4184 KB |
Output is correct |
2 |
Correct |
3 ms |
4184 KB |
Output is correct |
3 |
Correct |
2 ms |
4184 KB |
Output is correct |
4 |
Correct |
2 ms |
2648 KB |
Output is correct |
5 |
Correct |
2 ms |
2648 KB |
Output is correct |
6 |
Correct |
2 ms |
2904 KB |
Output is correct |
7 |
Correct |
3 ms |
2904 KB |
Output is correct |
8 |
Correct |
2 ms |
2904 KB |
Output is correct |
9 |
Correct |
4 ms |
2908 KB |
Output is correct |
10 |
Correct |
2 ms |
2904 KB |
Output is correct |
11 |
Correct |
2 ms |
2904 KB |
Output is correct |
12 |
Correct |
3 ms |
2904 KB |
Output is correct |
13 |
Correct |
452 ms |
9560 KB |
Output is correct |
14 |
Runtime error |
31 ms |
15536 KB |
Execution killed with signal 11 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2900 KB |
Output is correct |
2 |
Correct |
2 ms |
2648 KB |
Output is correct |
3 |
Correct |
2 ms |
2904 KB |
Output is correct |
4 |
Correct |
3 ms |
2904 KB |
Output is correct |
5 |
Correct |
2 ms |
2904 KB |
Output is correct |
6 |
Correct |
2 ms |
4184 KB |
Output is correct |
7 |
Correct |
2 ms |
2904 KB |
Output is correct |
8 |
Correct |
2 ms |
2904 KB |
Output is correct |
9 |
Correct |
2 ms |
4184 KB |
Output is correct |
10 |
Correct |
3 ms |
4184 KB |
Output is correct |
11 |
Correct |
2 ms |
4184 KB |
Output is correct |
12 |
Correct |
2 ms |
2648 KB |
Output is correct |
13 |
Correct |
2 ms |
2648 KB |
Output is correct |
14 |
Correct |
2 ms |
2904 KB |
Output is correct |
15 |
Correct |
3 ms |
2904 KB |
Output is correct |
16 |
Correct |
2 ms |
2904 KB |
Output is correct |
17 |
Correct |
4 ms |
2908 KB |
Output is correct |
18 |
Correct |
2 ms |
2904 KB |
Output is correct |
19 |
Correct |
2 ms |
2904 KB |
Output is correct |
20 |
Correct |
3 ms |
2904 KB |
Output is correct |
21 |
Correct |
2 ms |
4440 KB |
Output is correct |
22 |
Correct |
2 ms |
4184 KB |
Output is correct |
23 |
Correct |
2 ms |
4184 KB |
Output is correct |
24 |
Correct |
3 ms |
4440 KB |
Output is correct |
25 |
Correct |
3 ms |
4440 KB |
Output is correct |
26 |
Correct |
3 ms |
2904 KB |
Output is correct |
27 |
Correct |
2 ms |
2904 KB |
Output is correct |
28 |
Correct |
2 ms |
2904 KB |
Output is correct |
29 |
Correct |
2 ms |
2904 KB |
Output is correct |
30 |
Correct |
2 ms |
2904 KB |
Output is correct |
31 |
Correct |
2 ms |
2812 KB |
Output is correct |
32 |
Correct |
2 ms |
2904 KB |
Output is correct |
33 |
Correct |
2 ms |
4440 KB |
Output is correct |
34 |
Correct |
3 ms |
2904 KB |
Output is correct |
35 |
Correct |
3 ms |
2912 KB |
Output is correct |
36 |
Correct |
3 ms |
4440 KB |
Output is correct |
37 |
Correct |
4 ms |
4440 KB |
Output is correct |
38 |
Correct |
2 ms |
2992 KB |
Output is correct |
39 |
Correct |
2 ms |
2904 KB |
Output is correct |
40 |
Correct |
2 ms |
3156 KB |
Output is correct |
41 |
Correct |
2 ms |
4184 KB |
Output is correct |
42 |
Correct |
2 ms |
2904 KB |
Output is correct |
43 |
Correct |
414 ms |
4696 KB |
Output is correct |
44 |
Correct |
579 ms |
3160 KB |
Output is correct |
45 |
Correct |
618 ms |
3416 KB |
Output is correct |
46 |
Correct |
573 ms |
5208 KB |
Output is correct |
47 |
Correct |
562 ms |
5208 KB |
Output is correct |
48 |
Correct |
584 ms |
3672 KB |
Output is correct |
49 |
Correct |
578 ms |
3672 KB |
Output is correct |
50 |
Correct |
536 ms |
3672 KB |
Output is correct |
51 |
Correct |
515 ms |
4952 KB |
Output is correct |
52 |
Correct |
605 ms |
4952 KB |
Output is correct |
53 |
Correct |
465 ms |
5464 KB |
Output is correct |
54 |
Correct |
539 ms |
5208 KB |
Output is correct |
55 |
Correct |
586 ms |
3672 KB |
Output is correct |
56 |
Correct |
640 ms |
5204 KB |
Output is correct |
57 |
Correct |
640 ms |
5204 KB |
Output is correct |
58 |
Correct |
603 ms |
5720 KB |
Output is correct |
59 |
Correct |
559 ms |
5976 KB |
Output is correct |
60 |
Correct |
603 ms |
4440 KB |
Output is correct |
61 |
Correct |
565 ms |
3420 KB |
Output is correct |
62 |
Correct |
587 ms |
3416 KB |
Output is correct |
63 |
Correct |
598 ms |
4696 KB |
Output is correct |
64 |
Correct |
552 ms |
3416 KB |
Output is correct |
65 |
Correct |
248 ms |
4440 KB |
Output is correct |
66 |
Correct |
575 ms |
3416 KB |
Output is correct |
67 |
Correct |
562 ms |
4952 KB |
Output is correct |
68 |
Correct |
494 ms |
3416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2900 KB |
Output is correct |
2 |
Correct |
2 ms |
2648 KB |
Output is correct |
3 |
Correct |
2 ms |
2904 KB |
Output is correct |
4 |
Correct |
3 ms |
2904 KB |
Output is correct |
5 |
Correct |
2 ms |
2904 KB |
Output is correct |
6 |
Correct |
2 ms |
4184 KB |
Output is correct |
7 |
Correct |
2 ms |
2904 KB |
Output is correct |
8 |
Correct |
2 ms |
2904 KB |
Output is correct |
9 |
Correct |
2 ms |
4184 KB |
Output is correct |
10 |
Correct |
3 ms |
4184 KB |
Output is correct |
11 |
Correct |
2 ms |
4184 KB |
Output is correct |
12 |
Correct |
2 ms |
2648 KB |
Output is correct |
13 |
Correct |
2 ms |
2648 KB |
Output is correct |
14 |
Correct |
2 ms |
2904 KB |
Output is correct |
15 |
Correct |
3 ms |
2904 KB |
Output is correct |
16 |
Correct |
2 ms |
2904 KB |
Output is correct |
17 |
Correct |
4 ms |
2908 KB |
Output is correct |
18 |
Correct |
2 ms |
2904 KB |
Output is correct |
19 |
Correct |
2 ms |
2904 KB |
Output is correct |
20 |
Correct |
3 ms |
2904 KB |
Output is correct |
21 |
Correct |
2 ms |
4440 KB |
Output is correct |
22 |
Correct |
2 ms |
4184 KB |
Output is correct |
23 |
Correct |
2 ms |
4184 KB |
Output is correct |
24 |
Correct |
3 ms |
4440 KB |
Output is correct |
25 |
Correct |
3 ms |
4440 KB |
Output is correct |
26 |
Correct |
3 ms |
2904 KB |
Output is correct |
27 |
Correct |
2 ms |
2904 KB |
Output is correct |
28 |
Correct |
2 ms |
2904 KB |
Output is correct |
29 |
Correct |
2 ms |
2904 KB |
Output is correct |
30 |
Correct |
2 ms |
2904 KB |
Output is correct |
31 |
Correct |
2 ms |
2812 KB |
Output is correct |
32 |
Correct |
2 ms |
2904 KB |
Output is correct |
33 |
Correct |
2 ms |
4440 KB |
Output is correct |
34 |
Correct |
3 ms |
2904 KB |
Output is correct |
35 |
Correct |
3 ms |
2912 KB |
Output is correct |
36 |
Correct |
3 ms |
4440 KB |
Output is correct |
37 |
Correct |
4 ms |
4440 KB |
Output is correct |
38 |
Correct |
2 ms |
2992 KB |
Output is correct |
39 |
Correct |
2 ms |
2904 KB |
Output is correct |
40 |
Correct |
2 ms |
3156 KB |
Output is correct |
41 |
Correct |
2 ms |
4184 KB |
Output is correct |
42 |
Correct |
2 ms |
2904 KB |
Output is correct |
43 |
Correct |
452 ms |
9560 KB |
Output is correct |
44 |
Runtime error |
31 ms |
15536 KB |
Execution killed with signal 11 |
45 |
Halted |
0 ms |
0 KB |
- |