#include <bits/stdc++.h>
#include "circuit.h"
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pli pair<long long,int>
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
#define pil pair<int,long long>
const long long du = 1000002022;
const int maxn = 2e5 + 9;
vector<int>a[maxn];
long long sub[maxn];
void dfs(int u) {
sub[u] = 1;
if (!a[u].empty()) {
sub[u] = (sub[u] * sz(a[u]));
for (auto v : a[u]) {
dfs(v);
sub[u] = (sub[u] * sub[v]) % du;
}
}
}
long long up[maxn];
void redfs(int u) {
long long dd = 1;
for (auto v : a[u]) {
up[v] = (up[v] * up[u]) % du;
up[v] = (up[v] * dd) % du;
dd = (dd * sub[v]) % du;
}
reverse(all(a[u]));
dd = 1;
for (auto v : a[u]) {
up[v] = (up[v] * dd) % du;
dd = (dd * sub[v]) % du;
}
for (auto v : a[u]) {
redfs(v);
}
}
struct node {
long long val, sum;
int lazy;
} st[maxn * 4];
int n, m;
void build(int id, int l, int r) {
st[id].lazy = 0;
if (l == r) {
st[id].val = st[id].sum = up[l + n];
return;
}
int mid = (l + r) / 2;
build(id * 2, l, mid);
build(id * 2 + 1, mid + 1, r);
st[id].sum = (st[id * 2].sum + st[id * 2 + 1].sum) % du;
st[id].val = st[id].sum;
}
void push(int id) {
if (st[id].lazy % 2 == 1) {
st[id * 2].lazy += st[id].lazy;
st[id * 2 + 1].lazy += st[id].lazy;
st[id * 2].val = (st[id * 2].sum - st[id * 2].val + 2 * du) % du;
st[id * 2 + 1].val = (st[id * 2 + 1].sum - st[id * 2 + 1].val + 2 * du) % du;
st[id].lazy = 0;
} else {
st[id * 2].lazy += st[id].lazy;
st[id * 2 + 1].lazy += st[id].lazy;
st[id].lazy = 0;
}
}
void update(int id, int l, int r, int u, int v) {
if (l > v || r < u || u > v)
return;
if (u <= l && r <= v) {
st[id].lazy++;
st[id].val = (st[id].sum - st[id].val + 2 * du) % du;
return;
}
int mid = (l + r) / 2;
push(id);
update(id * 2, l, mid, u, v);
update(id * 2 + 1, mid + 1, r, u, v);
st[id].val = (st[id * 2].val + st[id * 2 + 1].val) % du;
}
int count_ways(int l, int r) {
l -= n - 1, r -= n - 1;
update(1, 1, m, l, r);
return st[1].val;
}
void init(int N, int M, vector<int>P, vector<int>A) {
n = N, m = M;
for1(i, 0, n + m - 1) {
if (P[i] != -1)
a[P[i] + 1].pb(i + 1);
}
dfs(1);
for1(i, 1, n + m)up[i] = 1;
redfs(1);
build(1, 1, m);
for1(i, 1, m)if (!A[i - 1])
update(1, 1, m, i, i);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8280 KB |
Output is correct |
2 |
Correct |
2 ms |
8280 KB |
Output is correct |
3 |
Correct |
2 ms |
8280 KB |
Output is correct |
4 |
Correct |
2 ms |
8280 KB |
Output is correct |
5 |
Correct |
2 ms |
8244 KB |
Output is correct |
6 |
Correct |
2 ms |
8280 KB |
Output is correct |
7 |
Correct |
2 ms |
8280 KB |
Output is correct |
8 |
Correct |
2 ms |
8280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8280 KB |
Output is correct |
2 |
Correct |
2 ms |
8280 KB |
Output is correct |
3 |
Correct |
2 ms |
8280 KB |
Output is correct |
4 |
Correct |
2 ms |
8280 KB |
Output is correct |
5 |
Correct |
3 ms |
8280 KB |
Output is correct |
6 |
Correct |
2 ms |
8280 KB |
Output is correct |
7 |
Correct |
3 ms |
8280 KB |
Output is correct |
8 |
Correct |
3 ms |
8280 KB |
Output is correct |
9 |
Correct |
2 ms |
8284 KB |
Output is correct |
10 |
Correct |
2 ms |
8536 KB |
Output is correct |
11 |
Correct |
2 ms |
8536 KB |
Output is correct |
12 |
Correct |
2 ms |
8348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8280 KB |
Output is correct |
2 |
Correct |
2 ms |
8280 KB |
Output is correct |
3 |
Correct |
2 ms |
8280 KB |
Output is correct |
4 |
Correct |
2 ms |
8280 KB |
Output is correct |
5 |
Correct |
2 ms |
8244 KB |
Output is correct |
6 |
Correct |
2 ms |
8280 KB |
Output is correct |
7 |
Correct |
2 ms |
8280 KB |
Output is correct |
8 |
Correct |
2 ms |
8280 KB |
Output is correct |
9 |
Correct |
2 ms |
8280 KB |
Output is correct |
10 |
Correct |
2 ms |
8280 KB |
Output is correct |
11 |
Correct |
2 ms |
8280 KB |
Output is correct |
12 |
Correct |
2 ms |
8280 KB |
Output is correct |
13 |
Correct |
3 ms |
8280 KB |
Output is correct |
14 |
Correct |
2 ms |
8280 KB |
Output is correct |
15 |
Correct |
3 ms |
8280 KB |
Output is correct |
16 |
Correct |
3 ms |
8280 KB |
Output is correct |
17 |
Correct |
2 ms |
8284 KB |
Output is correct |
18 |
Correct |
2 ms |
8536 KB |
Output is correct |
19 |
Correct |
2 ms |
8536 KB |
Output is correct |
20 |
Correct |
2 ms |
8348 KB |
Output is correct |
21 |
Correct |
2 ms |
8280 KB |
Output is correct |
22 |
Correct |
2 ms |
8280 KB |
Output is correct |
23 |
Correct |
2 ms |
8400 KB |
Output is correct |
24 |
Correct |
3 ms |
8280 KB |
Output is correct |
25 |
Correct |
3 ms |
8280 KB |
Output is correct |
26 |
Correct |
2 ms |
8368 KB |
Output is correct |
27 |
Correct |
2 ms |
8280 KB |
Output is correct |
28 |
Correct |
2 ms |
8280 KB |
Output is correct |
29 |
Correct |
2 ms |
8280 KB |
Output is correct |
30 |
Correct |
2 ms |
8280 KB |
Output is correct |
31 |
Correct |
2 ms |
8476 KB |
Output is correct |
32 |
Correct |
2 ms |
8280 KB |
Output is correct |
33 |
Correct |
2 ms |
8280 KB |
Output is correct |
34 |
Correct |
2 ms |
8280 KB |
Output is correct |
35 |
Correct |
2 ms |
8280 KB |
Output is correct |
36 |
Correct |
2 ms |
8536 KB |
Output is correct |
37 |
Correct |
2 ms |
8536 KB |
Output is correct |
38 |
Correct |
2 ms |
8536 KB |
Output is correct |
39 |
Correct |
2 ms |
8280 KB |
Output is correct |
40 |
Correct |
2 ms |
8280 KB |
Output is correct |
41 |
Correct |
2 ms |
8280 KB |
Output is correct |
42 |
Correct |
2 ms |
8280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
418 ms |
12444 KB |
Output is correct |
2 |
Correct |
573 ms |
16092 KB |
Output is correct |
3 |
Correct |
590 ms |
16100 KB |
Output is correct |
4 |
Correct |
623 ms |
16088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
418 ms |
12444 KB |
Output is correct |
2 |
Correct |
573 ms |
16092 KB |
Output is correct |
3 |
Correct |
590 ms |
16100 KB |
Output is correct |
4 |
Correct |
623 ms |
16088 KB |
Output is correct |
5 |
Correct |
498 ms |
12640 KB |
Output is correct |
6 |
Correct |
632 ms |
16256 KB |
Output is correct |
7 |
Correct |
608 ms |
16056 KB |
Output is correct |
8 |
Correct |
559 ms |
16164 KB |
Output is correct |
9 |
Correct |
252 ms |
8536 KB |
Output is correct |
10 |
Correct |
570 ms |
10840 KB |
Output is correct |
11 |
Correct |
580 ms |
10840 KB |
Output is correct |
12 |
Correct |
553 ms |
10840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8280 KB |
Output is correct |
2 |
Correct |
2 ms |
8280 KB |
Output is correct |
3 |
Correct |
2 ms |
8280 KB |
Output is correct |
4 |
Correct |
2 ms |
8280 KB |
Output is correct |
5 |
Correct |
3 ms |
8280 KB |
Output is correct |
6 |
Correct |
2 ms |
8280 KB |
Output is correct |
7 |
Correct |
3 ms |
8280 KB |
Output is correct |
8 |
Correct |
3 ms |
8280 KB |
Output is correct |
9 |
Correct |
2 ms |
8284 KB |
Output is correct |
10 |
Correct |
2 ms |
8536 KB |
Output is correct |
11 |
Correct |
2 ms |
8536 KB |
Output is correct |
12 |
Correct |
2 ms |
8348 KB |
Output is correct |
13 |
Correct |
418 ms |
12444 KB |
Output is correct |
14 |
Correct |
573 ms |
16092 KB |
Output is correct |
15 |
Correct |
590 ms |
16100 KB |
Output is correct |
16 |
Correct |
623 ms |
16088 KB |
Output is correct |
17 |
Correct |
498 ms |
12640 KB |
Output is correct |
18 |
Correct |
632 ms |
16256 KB |
Output is correct |
19 |
Correct |
608 ms |
16056 KB |
Output is correct |
20 |
Correct |
559 ms |
16164 KB |
Output is correct |
21 |
Correct |
252 ms |
8536 KB |
Output is correct |
22 |
Correct |
570 ms |
10840 KB |
Output is correct |
23 |
Correct |
580 ms |
10840 KB |
Output is correct |
24 |
Correct |
553 ms |
10840 KB |
Output is correct |
25 |
Correct |
652 ms |
19940 KB |
Output is correct |
26 |
Correct |
677 ms |
20064 KB |
Output is correct |
27 |
Correct |
659 ms |
20048 KB |
Output is correct |
28 |
Correct |
523 ms |
20028 KB |
Output is correct |
29 |
Correct |
709 ms |
26208 KB |
Output is correct |
30 |
Correct |
645 ms |
26296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8280 KB |
Output is correct |
2 |
Correct |
2 ms |
8280 KB |
Output is correct |
3 |
Correct |
2 ms |
8280 KB |
Output is correct |
4 |
Correct |
2 ms |
8280 KB |
Output is correct |
5 |
Correct |
2 ms |
8244 KB |
Output is correct |
6 |
Correct |
2 ms |
8280 KB |
Output is correct |
7 |
Correct |
2 ms |
8280 KB |
Output is correct |
8 |
Correct |
2 ms |
8280 KB |
Output is correct |
9 |
Correct |
2 ms |
8280 KB |
Output is correct |
10 |
Correct |
2 ms |
8280 KB |
Output is correct |
11 |
Correct |
2 ms |
8280 KB |
Output is correct |
12 |
Correct |
2 ms |
8280 KB |
Output is correct |
13 |
Correct |
3 ms |
8280 KB |
Output is correct |
14 |
Correct |
2 ms |
8280 KB |
Output is correct |
15 |
Correct |
3 ms |
8280 KB |
Output is correct |
16 |
Correct |
3 ms |
8280 KB |
Output is correct |
17 |
Correct |
2 ms |
8284 KB |
Output is correct |
18 |
Correct |
2 ms |
8536 KB |
Output is correct |
19 |
Correct |
2 ms |
8536 KB |
Output is correct |
20 |
Correct |
2 ms |
8348 KB |
Output is correct |
21 |
Correct |
2 ms |
8280 KB |
Output is correct |
22 |
Correct |
2 ms |
8280 KB |
Output is correct |
23 |
Correct |
2 ms |
8400 KB |
Output is correct |
24 |
Correct |
3 ms |
8280 KB |
Output is correct |
25 |
Correct |
3 ms |
8280 KB |
Output is correct |
26 |
Correct |
2 ms |
8368 KB |
Output is correct |
27 |
Correct |
2 ms |
8280 KB |
Output is correct |
28 |
Correct |
2 ms |
8280 KB |
Output is correct |
29 |
Correct |
2 ms |
8280 KB |
Output is correct |
30 |
Correct |
2 ms |
8280 KB |
Output is correct |
31 |
Correct |
2 ms |
8476 KB |
Output is correct |
32 |
Correct |
2 ms |
8280 KB |
Output is correct |
33 |
Correct |
2 ms |
8280 KB |
Output is correct |
34 |
Correct |
2 ms |
8280 KB |
Output is correct |
35 |
Correct |
2 ms |
8280 KB |
Output is correct |
36 |
Correct |
2 ms |
8536 KB |
Output is correct |
37 |
Correct |
2 ms |
8536 KB |
Output is correct |
38 |
Correct |
2 ms |
8536 KB |
Output is correct |
39 |
Correct |
2 ms |
8280 KB |
Output is correct |
40 |
Correct |
2 ms |
8280 KB |
Output is correct |
41 |
Correct |
2 ms |
8280 KB |
Output is correct |
42 |
Correct |
2 ms |
8280 KB |
Output is correct |
43 |
Correct |
382 ms |
10584 KB |
Output is correct |
44 |
Correct |
539 ms |
10584 KB |
Output is correct |
45 |
Correct |
581 ms |
10584 KB |
Output is correct |
46 |
Correct |
528 ms |
10840 KB |
Output is correct |
47 |
Correct |
563 ms |
10840 KB |
Output is correct |
48 |
Correct |
560 ms |
10840 KB |
Output is correct |
49 |
Correct |
576 ms |
10840 KB |
Output is correct |
50 |
Correct |
539 ms |
10840 KB |
Output is correct |
51 |
Correct |
523 ms |
10584 KB |
Output is correct |
52 |
Correct |
538 ms |
10584 KB |
Output is correct |
53 |
Correct |
531 ms |
8788 KB |
Output is correct |
54 |
Correct |
572 ms |
10840 KB |
Output is correct |
55 |
Correct |
568 ms |
10584 KB |
Output is correct |
56 |
Correct |
580 ms |
10584 KB |
Output is correct |
57 |
Correct |
573 ms |
10584 KB |
Output is correct |
58 |
Correct |
536 ms |
11096 KB |
Output is correct |
59 |
Correct |
547 ms |
11248 KB |
Output is correct |
60 |
Correct |
522 ms |
11248 KB |
Output is correct |
61 |
Correct |
573 ms |
10840 KB |
Output is correct |
62 |
Correct |
552 ms |
10584 KB |
Output is correct |
63 |
Correct |
551 ms |
10584 KB |
Output is correct |
64 |
Correct |
587 ms |
10584 KB |
Output is correct |
65 |
Correct |
276 ms |
8536 KB |
Output is correct |
66 |
Correct |
566 ms |
10840 KB |
Output is correct |
67 |
Correct |
570 ms |
10840 KB |
Output is correct |
68 |
Correct |
543 ms |
10840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8280 KB |
Output is correct |
2 |
Correct |
2 ms |
8280 KB |
Output is correct |
3 |
Correct |
2 ms |
8280 KB |
Output is correct |
4 |
Correct |
2 ms |
8280 KB |
Output is correct |
5 |
Correct |
2 ms |
8244 KB |
Output is correct |
6 |
Correct |
2 ms |
8280 KB |
Output is correct |
7 |
Correct |
2 ms |
8280 KB |
Output is correct |
8 |
Correct |
2 ms |
8280 KB |
Output is correct |
9 |
Correct |
2 ms |
8280 KB |
Output is correct |
10 |
Correct |
2 ms |
8280 KB |
Output is correct |
11 |
Correct |
2 ms |
8280 KB |
Output is correct |
12 |
Correct |
2 ms |
8280 KB |
Output is correct |
13 |
Correct |
3 ms |
8280 KB |
Output is correct |
14 |
Correct |
2 ms |
8280 KB |
Output is correct |
15 |
Correct |
3 ms |
8280 KB |
Output is correct |
16 |
Correct |
3 ms |
8280 KB |
Output is correct |
17 |
Correct |
2 ms |
8284 KB |
Output is correct |
18 |
Correct |
2 ms |
8536 KB |
Output is correct |
19 |
Correct |
2 ms |
8536 KB |
Output is correct |
20 |
Correct |
2 ms |
8348 KB |
Output is correct |
21 |
Correct |
2 ms |
8280 KB |
Output is correct |
22 |
Correct |
2 ms |
8280 KB |
Output is correct |
23 |
Correct |
2 ms |
8400 KB |
Output is correct |
24 |
Correct |
3 ms |
8280 KB |
Output is correct |
25 |
Correct |
3 ms |
8280 KB |
Output is correct |
26 |
Correct |
2 ms |
8368 KB |
Output is correct |
27 |
Correct |
2 ms |
8280 KB |
Output is correct |
28 |
Correct |
2 ms |
8280 KB |
Output is correct |
29 |
Correct |
2 ms |
8280 KB |
Output is correct |
30 |
Correct |
2 ms |
8280 KB |
Output is correct |
31 |
Correct |
2 ms |
8476 KB |
Output is correct |
32 |
Correct |
2 ms |
8280 KB |
Output is correct |
33 |
Correct |
2 ms |
8280 KB |
Output is correct |
34 |
Correct |
2 ms |
8280 KB |
Output is correct |
35 |
Correct |
2 ms |
8280 KB |
Output is correct |
36 |
Correct |
2 ms |
8536 KB |
Output is correct |
37 |
Correct |
2 ms |
8536 KB |
Output is correct |
38 |
Correct |
2 ms |
8536 KB |
Output is correct |
39 |
Correct |
2 ms |
8280 KB |
Output is correct |
40 |
Correct |
2 ms |
8280 KB |
Output is correct |
41 |
Correct |
2 ms |
8280 KB |
Output is correct |
42 |
Correct |
2 ms |
8280 KB |
Output is correct |
43 |
Correct |
418 ms |
12444 KB |
Output is correct |
44 |
Correct |
573 ms |
16092 KB |
Output is correct |
45 |
Correct |
590 ms |
16100 KB |
Output is correct |
46 |
Correct |
623 ms |
16088 KB |
Output is correct |
47 |
Correct |
498 ms |
12640 KB |
Output is correct |
48 |
Correct |
632 ms |
16256 KB |
Output is correct |
49 |
Correct |
608 ms |
16056 KB |
Output is correct |
50 |
Correct |
559 ms |
16164 KB |
Output is correct |
51 |
Correct |
252 ms |
8536 KB |
Output is correct |
52 |
Correct |
570 ms |
10840 KB |
Output is correct |
53 |
Correct |
580 ms |
10840 KB |
Output is correct |
54 |
Correct |
553 ms |
10840 KB |
Output is correct |
55 |
Correct |
652 ms |
19940 KB |
Output is correct |
56 |
Correct |
677 ms |
20064 KB |
Output is correct |
57 |
Correct |
659 ms |
20048 KB |
Output is correct |
58 |
Correct |
523 ms |
20028 KB |
Output is correct |
59 |
Correct |
709 ms |
26208 KB |
Output is correct |
60 |
Correct |
645 ms |
26296 KB |
Output is correct |
61 |
Correct |
382 ms |
10584 KB |
Output is correct |
62 |
Correct |
539 ms |
10584 KB |
Output is correct |
63 |
Correct |
581 ms |
10584 KB |
Output is correct |
64 |
Correct |
528 ms |
10840 KB |
Output is correct |
65 |
Correct |
563 ms |
10840 KB |
Output is correct |
66 |
Correct |
560 ms |
10840 KB |
Output is correct |
67 |
Correct |
576 ms |
10840 KB |
Output is correct |
68 |
Correct |
539 ms |
10840 KB |
Output is correct |
69 |
Correct |
523 ms |
10584 KB |
Output is correct |
70 |
Correct |
538 ms |
10584 KB |
Output is correct |
71 |
Correct |
531 ms |
8788 KB |
Output is correct |
72 |
Correct |
572 ms |
10840 KB |
Output is correct |
73 |
Correct |
568 ms |
10584 KB |
Output is correct |
74 |
Correct |
580 ms |
10584 KB |
Output is correct |
75 |
Correct |
573 ms |
10584 KB |
Output is correct |
76 |
Correct |
536 ms |
11096 KB |
Output is correct |
77 |
Correct |
547 ms |
11248 KB |
Output is correct |
78 |
Correct |
522 ms |
11248 KB |
Output is correct |
79 |
Correct |
573 ms |
10840 KB |
Output is correct |
80 |
Correct |
552 ms |
10584 KB |
Output is correct |
81 |
Correct |
551 ms |
10584 KB |
Output is correct |
82 |
Correct |
587 ms |
10584 KB |
Output is correct |
83 |
Correct |
276 ms |
8536 KB |
Output is correct |
84 |
Correct |
566 ms |
10840 KB |
Output is correct |
85 |
Correct |
570 ms |
10840 KB |
Output is correct |
86 |
Correct |
543 ms |
10840 KB |
Output is correct |
87 |
Correct |
2 ms |
8280 KB |
Output is correct |
88 |
Correct |
388 ms |
19800 KB |
Output is correct |
89 |
Correct |
674 ms |
16520 KB |
Output is correct |
90 |
Correct |
636 ms |
16008 KB |
Output is correct |
91 |
Correct |
634 ms |
20060 KB |
Output is correct |
92 |
Correct |
713 ms |
20312 KB |
Output is correct |
93 |
Correct |
716 ms |
20320 KB |
Output is correct |
94 |
Correct |
701 ms |
20324 KB |
Output is correct |
95 |
Correct |
618 ms |
20316 KB |
Output is correct |
96 |
Correct |
568 ms |
16592 KB |
Output is correct |
97 |
Correct |
618 ms |
16592 KB |
Output is correct |
98 |
Correct |
576 ms |
18540 KB |
Output is correct |
99 |
Correct |
738 ms |
20016 KB |
Output is correct |
100 |
Correct |
662 ms |
18096 KB |
Output is correct |
101 |
Correct |
707 ms |
17744 KB |
Output is correct |
102 |
Correct |
676 ms |
16556 KB |
Output is correct |
103 |
Correct |
674 ms |
26620 KB |
Output is correct |
104 |
Correct |
611 ms |
26860 KB |
Output is correct |
105 |
Correct |
575 ms |
26848 KB |
Output is correct |
106 |
Correct |
587 ms |
17468 KB |
Output is correct |
107 |
Correct |
559 ms |
17408 KB |
Output is correct |
108 |
Correct |
617 ms |
17076 KB |
Output is correct |
109 |
Correct |
635 ms |
16976 KB |
Output is correct |