#include <bits/stdc++.h>
#include "circuit.h"
using namespace std;
#define int long long
const int MXN = 2e5 + 5;
const int mod = 1e9 + 2022;
int n, m, res = 0;
vector<int> A, P;
vector<int> adj[MXN];
int dp[2][MXN], SZ[MXN];
int way[MXN];
void _init(int a)
{
if (adj[a].empty())
{
way[a] = 1;
return;
}
way[a] = adj[a].size();
for (int &v : adj[a])
{
_init(v);
way[a] = (way[a] * way[v]) % mod;
}
}
int val[MXN];
array<int, 2> st[MXN << 2];
int lz[MXN << 2];
void relax(int l, int r, int x)
{
if (!lz[x]) return;
swap(st[x][0], st[x][1]);
if (l == r)
{
lz[x] = 0;
return;
}
lz[2*x] ^= lz[x], lz[2*x + 1] ^= lz[x];
lz[x] = 0;
}
void upd(int l, int r, int x, int lx, int rx)
{
relax(l, r, x);
if (l > rx || r < lx) return;
if (l >= lx && r <= rx)
{
lz[x] ^= 1;
relax(l, r, x);
return;
}
int mid = (l + r) >> 1;
upd(l, mid, 2*x, lx, rx);
upd(mid + 1, r, 2*x + 1, lx, rx);
st[x][0] = (st[2*x][0] + st[2*x + 1][0]) % mod;
st[x][1] = (st[2*x][1] + st[2*x + 1][1]) % mod;
}
void build(int l, int r, int x)
{
if (l == r)
{
st[x][0] = A[l] * val[l];
st[x][1] = (A[l] ^ 1) * val[l];
return;
}
int mid = (l + r) >> 1;
build(l, mid, 2*x);
build(mid + 1, r, 2*x + 1);
st[x][0] = (st[2*x][0] + st[2*x + 1][0]) % mod;
st[x][1] = (st[2*x][1] + st[2*x + 1][1]) % mod;
}
void init(int32_t N, int32_t M, vector<int32_t> PP, vector<int32_t> AA)
{
n = N, m = M;
for (int32_t &i : PP) P.push_back(i);
for (int32_t &i : AA) A.push_back(i);
reverse(A.begin(), A.end());
A.resize(N + M, 0);
reverse(A.begin(), A.end());
for (int i = 1; i < N + M; i++) adj[P[i]].push_back(i);
_init(0);
for (int i = N; i < N + M; i++)
{
int x = i;
val[i] = 1;
while (P[x] != -1)
{
for (int &v : adj[P[x]])
{
if (v == x) continue;
val[i] = (val[i] * way[v]) % mod;
}
x = P[x];
}
}
build(N, N + M - 1, 1);
}
int32_t count_ways(int32_t L, int32_t R) {
upd(n, n + m - 1, 1, L, R);
return st[1][0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
10840 KB |
Output is correct |
2 |
Correct |
1 ms |
10840 KB |
Output is correct |
3 |
Correct |
5 ms |
11096 KB |
Output is correct |
4 |
Correct |
5 ms |
11096 KB |
Output is correct |
5 |
Correct |
5 ms |
11096 KB |
Output is correct |
6 |
Correct |
5 ms |
11100 KB |
Output is correct |
7 |
Correct |
5 ms |
11096 KB |
Output is correct |
8 |
Correct |
5 ms |
11096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10840 KB |
Output is correct |
2 |
Correct |
1 ms |
10840 KB |
Output is correct |
3 |
Correct |
1 ms |
11096 KB |
Output is correct |
4 |
Correct |
2 ms |
11096 KB |
Output is correct |
5 |
Correct |
1 ms |
11096 KB |
Output is correct |
6 |
Correct |
1 ms |
11096 KB |
Output is correct |
7 |
Correct |
1 ms |
11096 KB |
Output is correct |
8 |
Correct |
1 ms |
11096 KB |
Output is correct |
9 |
Correct |
1 ms |
11096 KB |
Output is correct |
10 |
Correct |
3 ms |
11180 KB |
Output is correct |
11 |
Correct |
3 ms |
11096 KB |
Output is correct |
12 |
Correct |
1 ms |
11096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
10840 KB |
Output is correct |
2 |
Correct |
1 ms |
10840 KB |
Output is correct |
3 |
Correct |
5 ms |
11096 KB |
Output is correct |
4 |
Correct |
5 ms |
11096 KB |
Output is correct |
5 |
Correct |
5 ms |
11096 KB |
Output is correct |
6 |
Correct |
5 ms |
11100 KB |
Output is correct |
7 |
Correct |
5 ms |
11096 KB |
Output is correct |
8 |
Correct |
5 ms |
11096 KB |
Output is correct |
9 |
Correct |
2 ms |
10840 KB |
Output is correct |
10 |
Correct |
1 ms |
10840 KB |
Output is correct |
11 |
Correct |
1 ms |
11096 KB |
Output is correct |
12 |
Correct |
2 ms |
11096 KB |
Output is correct |
13 |
Correct |
1 ms |
11096 KB |
Output is correct |
14 |
Correct |
1 ms |
11096 KB |
Output is correct |
15 |
Correct |
1 ms |
11096 KB |
Output is correct |
16 |
Correct |
1 ms |
11096 KB |
Output is correct |
17 |
Correct |
1 ms |
11096 KB |
Output is correct |
18 |
Correct |
3 ms |
11180 KB |
Output is correct |
19 |
Correct |
3 ms |
11096 KB |
Output is correct |
20 |
Correct |
1 ms |
11096 KB |
Output is correct |
21 |
Correct |
1 ms |
11096 KB |
Output is correct |
22 |
Correct |
2 ms |
11096 KB |
Output is correct |
23 |
Correct |
1 ms |
10928 KB |
Output is correct |
24 |
Correct |
1 ms |
11096 KB |
Output is correct |
25 |
Correct |
1 ms |
11096 KB |
Output is correct |
26 |
Correct |
2 ms |
11096 KB |
Output is correct |
27 |
Correct |
2 ms |
11096 KB |
Output is correct |
28 |
Correct |
2 ms |
11096 KB |
Output is correct |
29 |
Correct |
5 ms |
10940 KB |
Output is correct |
30 |
Correct |
5 ms |
11096 KB |
Output is correct |
31 |
Correct |
1 ms |
11096 KB |
Output is correct |
32 |
Correct |
1 ms |
11096 KB |
Output is correct |
33 |
Correct |
2 ms |
11096 KB |
Output is correct |
34 |
Correct |
2 ms |
11096 KB |
Output is correct |
35 |
Correct |
3 ms |
11092 KB |
Output is correct |
36 |
Correct |
3 ms |
11096 KB |
Output is correct |
37 |
Correct |
7 ms |
11096 KB |
Output is correct |
38 |
Correct |
7 ms |
11196 KB |
Output is correct |
39 |
Correct |
2 ms |
11096 KB |
Output is correct |
40 |
Correct |
1 ms |
11096 KB |
Output is correct |
41 |
Correct |
1 ms |
11096 KB |
Output is correct |
42 |
Correct |
2 ms |
11092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
357 ms |
18004 KB |
Output is correct |
2 |
Correct |
487 ms |
20816 KB |
Output is correct |
3 |
Correct |
580 ms |
20696 KB |
Output is correct |
4 |
Correct |
534 ms |
20568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
357 ms |
18004 KB |
Output is correct |
2 |
Correct |
487 ms |
20816 KB |
Output is correct |
3 |
Correct |
580 ms |
20696 KB |
Output is correct |
4 |
Correct |
534 ms |
20568 KB |
Output is correct |
5 |
Correct |
474 ms |
18144 KB |
Output is correct |
6 |
Correct |
616 ms |
22344 KB |
Output is correct |
7 |
Correct |
609 ms |
21076 KB |
Output is correct |
8 |
Correct |
554 ms |
22124 KB |
Output is correct |
9 |
Correct |
264 ms |
11096 KB |
Output is correct |
10 |
Correct |
592 ms |
13400 KB |
Output is correct |
11 |
Correct |
567 ms |
13400 KB |
Output is correct |
12 |
Correct |
517 ms |
13400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10840 KB |
Output is correct |
2 |
Correct |
1 ms |
10840 KB |
Output is correct |
3 |
Correct |
1 ms |
11096 KB |
Output is correct |
4 |
Correct |
2 ms |
11096 KB |
Output is correct |
5 |
Correct |
1 ms |
11096 KB |
Output is correct |
6 |
Correct |
1 ms |
11096 KB |
Output is correct |
7 |
Correct |
1 ms |
11096 KB |
Output is correct |
8 |
Correct |
1 ms |
11096 KB |
Output is correct |
9 |
Correct |
1 ms |
11096 KB |
Output is correct |
10 |
Correct |
3 ms |
11180 KB |
Output is correct |
11 |
Correct |
3 ms |
11096 KB |
Output is correct |
12 |
Correct |
1 ms |
11096 KB |
Output is correct |
13 |
Correct |
357 ms |
18004 KB |
Output is correct |
14 |
Correct |
487 ms |
20816 KB |
Output is correct |
15 |
Correct |
580 ms |
20696 KB |
Output is correct |
16 |
Correct |
534 ms |
20568 KB |
Output is correct |
17 |
Correct |
474 ms |
18144 KB |
Output is correct |
18 |
Correct |
616 ms |
22344 KB |
Output is correct |
19 |
Correct |
609 ms |
21076 KB |
Output is correct |
20 |
Correct |
554 ms |
22124 KB |
Output is correct |
21 |
Correct |
264 ms |
11096 KB |
Output is correct |
22 |
Correct |
592 ms |
13400 KB |
Output is correct |
23 |
Correct |
567 ms |
13400 KB |
Output is correct |
24 |
Correct |
517 ms |
13400 KB |
Output is correct |
25 |
Correct |
667 ms |
26572 KB |
Output is correct |
26 |
Correct |
652 ms |
26872 KB |
Output is correct |
27 |
Correct |
624 ms |
26712 KB |
Output is correct |
28 |
Correct |
514 ms |
25760 KB |
Output is correct |
29 |
Execution timed out |
3062 ms |
24380 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
10840 KB |
Output is correct |
2 |
Correct |
1 ms |
10840 KB |
Output is correct |
3 |
Correct |
5 ms |
11096 KB |
Output is correct |
4 |
Correct |
5 ms |
11096 KB |
Output is correct |
5 |
Correct |
5 ms |
11096 KB |
Output is correct |
6 |
Correct |
5 ms |
11100 KB |
Output is correct |
7 |
Correct |
5 ms |
11096 KB |
Output is correct |
8 |
Correct |
5 ms |
11096 KB |
Output is correct |
9 |
Correct |
2 ms |
10840 KB |
Output is correct |
10 |
Correct |
1 ms |
10840 KB |
Output is correct |
11 |
Correct |
1 ms |
11096 KB |
Output is correct |
12 |
Correct |
2 ms |
11096 KB |
Output is correct |
13 |
Correct |
1 ms |
11096 KB |
Output is correct |
14 |
Correct |
1 ms |
11096 KB |
Output is correct |
15 |
Correct |
1 ms |
11096 KB |
Output is correct |
16 |
Correct |
1 ms |
11096 KB |
Output is correct |
17 |
Correct |
1 ms |
11096 KB |
Output is correct |
18 |
Correct |
3 ms |
11180 KB |
Output is correct |
19 |
Correct |
3 ms |
11096 KB |
Output is correct |
20 |
Correct |
1 ms |
11096 KB |
Output is correct |
21 |
Correct |
1 ms |
11096 KB |
Output is correct |
22 |
Correct |
2 ms |
11096 KB |
Output is correct |
23 |
Correct |
1 ms |
10928 KB |
Output is correct |
24 |
Correct |
1 ms |
11096 KB |
Output is correct |
25 |
Correct |
1 ms |
11096 KB |
Output is correct |
26 |
Correct |
2 ms |
11096 KB |
Output is correct |
27 |
Correct |
2 ms |
11096 KB |
Output is correct |
28 |
Correct |
2 ms |
11096 KB |
Output is correct |
29 |
Correct |
5 ms |
10940 KB |
Output is correct |
30 |
Correct |
5 ms |
11096 KB |
Output is correct |
31 |
Correct |
1 ms |
11096 KB |
Output is correct |
32 |
Correct |
1 ms |
11096 KB |
Output is correct |
33 |
Correct |
2 ms |
11096 KB |
Output is correct |
34 |
Correct |
2 ms |
11096 KB |
Output is correct |
35 |
Correct |
3 ms |
11092 KB |
Output is correct |
36 |
Correct |
3 ms |
11096 KB |
Output is correct |
37 |
Correct |
7 ms |
11096 KB |
Output is correct |
38 |
Correct |
7 ms |
11196 KB |
Output is correct |
39 |
Correct |
2 ms |
11096 KB |
Output is correct |
40 |
Correct |
1 ms |
11096 KB |
Output is correct |
41 |
Correct |
1 ms |
11096 KB |
Output is correct |
42 |
Correct |
2 ms |
11092 KB |
Output is correct |
43 |
Correct |
377 ms |
13400 KB |
Output is correct |
44 |
Correct |
585 ms |
13400 KB |
Output is correct |
45 |
Correct |
586 ms |
13400 KB |
Output is correct |
46 |
Correct |
528 ms |
13656 KB |
Output is correct |
47 |
Correct |
532 ms |
13656 KB |
Output is correct |
48 |
Correct |
545 ms |
13656 KB |
Output is correct |
49 |
Correct |
374 ms |
13656 KB |
Output is correct |
50 |
Correct |
429 ms |
13400 KB |
Output is correct |
51 |
Correct |
637 ms |
13368 KB |
Output is correct |
52 |
Correct |
662 ms |
13476 KB |
Output is correct |
53 |
Correct |
466 ms |
11352 KB |
Output is correct |
54 |
Correct |
499 ms |
13656 KB |
Output is correct |
55 |
Correct |
566 ms |
13564 KB |
Output is correct |
56 |
Correct |
540 ms |
13400 KB |
Output is correct |
57 |
Correct |
563 ms |
13448 KB |
Output is correct |
58 |
Correct |
591 ms |
13648 KB |
Output is correct |
59 |
Correct |
710 ms |
13992 KB |
Output is correct |
60 |
Correct |
678 ms |
13880 KB |
Output is correct |
61 |
Correct |
528 ms |
13400 KB |
Output is correct |
62 |
Correct |
492 ms |
13400 KB |
Output is correct |
63 |
Correct |
537 ms |
13400 KB |
Output is correct |
64 |
Correct |
507 ms |
13400 KB |
Output is correct |
65 |
Correct |
259 ms |
11096 KB |
Output is correct |
66 |
Correct |
447 ms |
13396 KB |
Output is correct |
67 |
Correct |
472 ms |
13400 KB |
Output is correct |
68 |
Correct |
477 ms |
13400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
10840 KB |
Output is correct |
2 |
Correct |
1 ms |
10840 KB |
Output is correct |
3 |
Correct |
5 ms |
11096 KB |
Output is correct |
4 |
Correct |
5 ms |
11096 KB |
Output is correct |
5 |
Correct |
5 ms |
11096 KB |
Output is correct |
6 |
Correct |
5 ms |
11100 KB |
Output is correct |
7 |
Correct |
5 ms |
11096 KB |
Output is correct |
8 |
Correct |
5 ms |
11096 KB |
Output is correct |
9 |
Correct |
2 ms |
10840 KB |
Output is correct |
10 |
Correct |
1 ms |
10840 KB |
Output is correct |
11 |
Correct |
1 ms |
11096 KB |
Output is correct |
12 |
Correct |
2 ms |
11096 KB |
Output is correct |
13 |
Correct |
1 ms |
11096 KB |
Output is correct |
14 |
Correct |
1 ms |
11096 KB |
Output is correct |
15 |
Correct |
1 ms |
11096 KB |
Output is correct |
16 |
Correct |
1 ms |
11096 KB |
Output is correct |
17 |
Correct |
1 ms |
11096 KB |
Output is correct |
18 |
Correct |
3 ms |
11180 KB |
Output is correct |
19 |
Correct |
3 ms |
11096 KB |
Output is correct |
20 |
Correct |
1 ms |
11096 KB |
Output is correct |
21 |
Correct |
1 ms |
11096 KB |
Output is correct |
22 |
Correct |
2 ms |
11096 KB |
Output is correct |
23 |
Correct |
1 ms |
10928 KB |
Output is correct |
24 |
Correct |
1 ms |
11096 KB |
Output is correct |
25 |
Correct |
1 ms |
11096 KB |
Output is correct |
26 |
Correct |
2 ms |
11096 KB |
Output is correct |
27 |
Correct |
2 ms |
11096 KB |
Output is correct |
28 |
Correct |
2 ms |
11096 KB |
Output is correct |
29 |
Correct |
5 ms |
10940 KB |
Output is correct |
30 |
Correct |
5 ms |
11096 KB |
Output is correct |
31 |
Correct |
1 ms |
11096 KB |
Output is correct |
32 |
Correct |
1 ms |
11096 KB |
Output is correct |
33 |
Correct |
2 ms |
11096 KB |
Output is correct |
34 |
Correct |
2 ms |
11096 KB |
Output is correct |
35 |
Correct |
3 ms |
11092 KB |
Output is correct |
36 |
Correct |
3 ms |
11096 KB |
Output is correct |
37 |
Correct |
7 ms |
11096 KB |
Output is correct |
38 |
Correct |
7 ms |
11196 KB |
Output is correct |
39 |
Correct |
2 ms |
11096 KB |
Output is correct |
40 |
Correct |
1 ms |
11096 KB |
Output is correct |
41 |
Correct |
1 ms |
11096 KB |
Output is correct |
42 |
Correct |
2 ms |
11092 KB |
Output is correct |
43 |
Correct |
357 ms |
18004 KB |
Output is correct |
44 |
Correct |
487 ms |
20816 KB |
Output is correct |
45 |
Correct |
580 ms |
20696 KB |
Output is correct |
46 |
Correct |
534 ms |
20568 KB |
Output is correct |
47 |
Correct |
474 ms |
18144 KB |
Output is correct |
48 |
Correct |
616 ms |
22344 KB |
Output is correct |
49 |
Correct |
609 ms |
21076 KB |
Output is correct |
50 |
Correct |
554 ms |
22124 KB |
Output is correct |
51 |
Correct |
264 ms |
11096 KB |
Output is correct |
52 |
Correct |
592 ms |
13400 KB |
Output is correct |
53 |
Correct |
567 ms |
13400 KB |
Output is correct |
54 |
Correct |
517 ms |
13400 KB |
Output is correct |
55 |
Correct |
667 ms |
26572 KB |
Output is correct |
56 |
Correct |
652 ms |
26872 KB |
Output is correct |
57 |
Correct |
624 ms |
26712 KB |
Output is correct |
58 |
Correct |
514 ms |
25760 KB |
Output is correct |
59 |
Execution timed out |
3062 ms |
24380 KB |
Time limit exceeded |
60 |
Halted |
0 ms |
0 KB |
- |