#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
#define rall(s) s.rbegin(), s.rend()
#define all(s) s.begin(), s.end()
#define sz(s) (int) s.size()
#define s second
#define f first
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int N = 5e5, mod = 1000002022;
int n, m, is = 1;
vector<int> g[N], a(N);
vector<ll> pr[N], sf[N], val(N);
void calc(int u) {
for (int to: g[u]) {
calc(to);
}
int M = sz(g[u]);
if (!M) {
val[u] = 1;
return;
}
pr[u].resize(m);
sf[u].resize(m);
for (int i = 0; i < M; i++) {
if (i) pr[u][i] = pr[u][i - 1];
else pr[u][i] = 1;
pr[u][i] = (pr[u][i] * val[g[u][i]]) % mod;
}
for (int i = M - 1; i >= 0; i--) {
if (i < M - 1) sf[u][i] = sf[u][i + 1];
else sf[u][i] = 1;
sf[u][i] = (sf[u][i] * val[g[u][i]]) % mod;
}
val[u] = (pr[u][M - 1] * M) % mod;
}
ll vl[N];
void dfs(int u, int x) {
int M = sz(g[u]);
if (!M) {
vl[u - n] = x;
return;
}
for (int i = 0; i < M; i++) {
dfs(g[u][i], (((x * (i ? pr[u][i - 1] : 1ll)) % mod) * (i < M - 1 ? sf[u][i + 1] : 1ll)) % mod);
}
}
pll t[4 * N];
int swp[4 * N];
void bld(int u = 1, int tl = 0, int tr = m - 1) {
if (tl == tr) {
if (a[tl]) t[u].f = vl[tl];
else t[u].s = vl[tl];
return;
}
int mid = (tl + tr) / 2;
bld(u * 2, tl, mid);
bld(u * 2 + 1, mid + 1, tr);
t[u].f = (t[u * 2].f + t[u * 2 + 1].f) % mod;
t[u].s = (t[u * 2].s + t[u * 2 + 1].s) % mod;
}
void push(int u, int tl, int tr) {
if (!swp[u]) return;
swap(t[u].f, t[u].s);
if (tl < tr) {
swp[u * 2] ^= 1;
swp[u * 2 + 1] ^= 1;
}
swp[u] = 0;
}
void upd(int l, int r, int u = 1, int tl = 0, int tr = m - 1) {
push(u, tl, tr);
if (tl > r || tr < l) return;
if (tl >= l && tr <= r) {
swp[u] = 1;
push(u, tl, tr);
return;
}
int mid = (tl + tr) / 2;
upd(l, r, u * 2, tl, mid);
upd(l, r, u * 2 + 1, mid + 1, tr);
t[u].f = (t[u * 2].f + t[u * 2 + 1].f) % mod;
t[u].s = (t[u * 2].s + t[u * 2 + 1].s) % mod;
}
void init(int nn, int M, vector<int> P, vector<int> A) {
n = nn, m = M;
for (int i = 0; i < m; i++) a[i] = A[i];
for (int i = 1; i < n + m; i++) g[P[i]].push_back(i);
calc(0), dfs(0, 1), bld();
}
int count_ways(int l, int r) {
upd(l - n, r - n);
return t[1].f;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
47448 KB |
Output is correct |
2 |
Correct |
7 ms |
47448 KB |
Output is correct |
3 |
Correct |
8 ms |
47448 KB |
Output is correct |
4 |
Correct |
8 ms |
47448 KB |
Output is correct |
5 |
Correct |
7 ms |
47388 KB |
Output is correct |
6 |
Correct |
8 ms |
47448 KB |
Output is correct |
7 |
Correct |
7 ms |
47376 KB |
Output is correct |
8 |
Correct |
8 ms |
47448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
47448 KB |
Output is correct |
2 |
Correct |
8 ms |
48472 KB |
Output is correct |
3 |
Correct |
9 ms |
51544 KB |
Output is correct |
4 |
Correct |
9 ms |
51544 KB |
Output is correct |
5 |
Correct |
10 ms |
51624 KB |
Output is correct |
6 |
Correct |
11 ms |
55640 KB |
Output is correct |
7 |
Correct |
15 ms |
63064 KB |
Output is correct |
8 |
Correct |
14 ms |
63064 KB |
Output is correct |
9 |
Correct |
15 ms |
62980 KB |
Output is correct |
10 |
Correct |
14 ms |
63064 KB |
Output is correct |
11 |
Correct |
14 ms |
63064 KB |
Output is correct |
12 |
Correct |
12 ms |
58712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
47448 KB |
Output is correct |
2 |
Correct |
7 ms |
47448 KB |
Output is correct |
3 |
Correct |
8 ms |
47448 KB |
Output is correct |
4 |
Correct |
8 ms |
47448 KB |
Output is correct |
5 |
Correct |
7 ms |
47388 KB |
Output is correct |
6 |
Correct |
8 ms |
47448 KB |
Output is correct |
7 |
Correct |
7 ms |
47376 KB |
Output is correct |
8 |
Correct |
8 ms |
47448 KB |
Output is correct |
9 |
Correct |
10 ms |
47448 KB |
Output is correct |
10 |
Correct |
8 ms |
48472 KB |
Output is correct |
11 |
Correct |
9 ms |
51544 KB |
Output is correct |
12 |
Correct |
9 ms |
51544 KB |
Output is correct |
13 |
Correct |
10 ms |
51624 KB |
Output is correct |
14 |
Correct |
11 ms |
55640 KB |
Output is correct |
15 |
Correct |
15 ms |
63064 KB |
Output is correct |
16 |
Correct |
14 ms |
63064 KB |
Output is correct |
17 |
Correct |
15 ms |
62980 KB |
Output is correct |
18 |
Correct |
14 ms |
63064 KB |
Output is correct |
19 |
Correct |
14 ms |
63064 KB |
Output is correct |
20 |
Correct |
12 ms |
58712 KB |
Output is correct |
21 |
Correct |
12 ms |
57944 KB |
Output is correct |
22 |
Correct |
10 ms |
53592 KB |
Output is correct |
23 |
Correct |
10 ms |
53080 KB |
Output is correct |
24 |
Correct |
14 ms |
63064 KB |
Output is correct |
25 |
Correct |
18 ms |
63068 KB |
Output is correct |
26 |
Correct |
14 ms |
63064 KB |
Output is correct |
27 |
Correct |
14 ms |
63064 KB |
Output is correct |
28 |
Correct |
14 ms |
63000 KB |
Output is correct |
29 |
Correct |
8 ms |
47448 KB |
Output is correct |
30 |
Correct |
8 ms |
47448 KB |
Output is correct |
31 |
Correct |
10 ms |
47448 KB |
Output is correct |
32 |
Correct |
14 ms |
63064 KB |
Output is correct |
33 |
Correct |
11 ms |
55128 KB |
Output is correct |
34 |
Correct |
9 ms |
51288 KB |
Output is correct |
35 |
Correct |
8 ms |
47448 KB |
Output is correct |
36 |
Correct |
19 ms |
63064 KB |
Output is correct |
37 |
Correct |
16 ms |
63064 KB |
Output is correct |
38 |
Correct |
14 ms |
63160 KB |
Output is correct |
39 |
Correct |
10 ms |
52056 KB |
Output is correct |
40 |
Correct |
11 ms |
53848 KB |
Output is correct |
41 |
Correct |
10 ms |
52312 KB |
Output is correct |
42 |
Correct |
9 ms |
47960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
743 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
743 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
47448 KB |
Output is correct |
2 |
Correct |
8 ms |
48472 KB |
Output is correct |
3 |
Correct |
9 ms |
51544 KB |
Output is correct |
4 |
Correct |
9 ms |
51544 KB |
Output is correct |
5 |
Correct |
10 ms |
51624 KB |
Output is correct |
6 |
Correct |
11 ms |
55640 KB |
Output is correct |
7 |
Correct |
15 ms |
63064 KB |
Output is correct |
8 |
Correct |
14 ms |
63064 KB |
Output is correct |
9 |
Correct |
15 ms |
62980 KB |
Output is correct |
10 |
Correct |
14 ms |
63064 KB |
Output is correct |
11 |
Correct |
14 ms |
63064 KB |
Output is correct |
12 |
Correct |
12 ms |
58712 KB |
Output is correct |
13 |
Runtime error |
743 ms |
2097152 KB |
Execution killed with signal 9 |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
47448 KB |
Output is correct |
2 |
Correct |
7 ms |
47448 KB |
Output is correct |
3 |
Correct |
8 ms |
47448 KB |
Output is correct |
4 |
Correct |
8 ms |
47448 KB |
Output is correct |
5 |
Correct |
7 ms |
47388 KB |
Output is correct |
6 |
Correct |
8 ms |
47448 KB |
Output is correct |
7 |
Correct |
7 ms |
47376 KB |
Output is correct |
8 |
Correct |
8 ms |
47448 KB |
Output is correct |
9 |
Correct |
10 ms |
47448 KB |
Output is correct |
10 |
Correct |
8 ms |
48472 KB |
Output is correct |
11 |
Correct |
9 ms |
51544 KB |
Output is correct |
12 |
Correct |
9 ms |
51544 KB |
Output is correct |
13 |
Correct |
10 ms |
51624 KB |
Output is correct |
14 |
Correct |
11 ms |
55640 KB |
Output is correct |
15 |
Correct |
15 ms |
63064 KB |
Output is correct |
16 |
Correct |
14 ms |
63064 KB |
Output is correct |
17 |
Correct |
15 ms |
62980 KB |
Output is correct |
18 |
Correct |
14 ms |
63064 KB |
Output is correct |
19 |
Correct |
14 ms |
63064 KB |
Output is correct |
20 |
Correct |
12 ms |
58712 KB |
Output is correct |
21 |
Correct |
12 ms |
57944 KB |
Output is correct |
22 |
Correct |
10 ms |
53592 KB |
Output is correct |
23 |
Correct |
10 ms |
53080 KB |
Output is correct |
24 |
Correct |
14 ms |
63064 KB |
Output is correct |
25 |
Correct |
18 ms |
63068 KB |
Output is correct |
26 |
Correct |
14 ms |
63064 KB |
Output is correct |
27 |
Correct |
14 ms |
63064 KB |
Output is correct |
28 |
Correct |
14 ms |
63000 KB |
Output is correct |
29 |
Correct |
8 ms |
47448 KB |
Output is correct |
30 |
Correct |
8 ms |
47448 KB |
Output is correct |
31 |
Correct |
10 ms |
47448 KB |
Output is correct |
32 |
Correct |
14 ms |
63064 KB |
Output is correct |
33 |
Correct |
11 ms |
55128 KB |
Output is correct |
34 |
Correct |
9 ms |
51288 KB |
Output is correct |
35 |
Correct |
8 ms |
47448 KB |
Output is correct |
36 |
Correct |
19 ms |
63064 KB |
Output is correct |
37 |
Correct |
16 ms |
63064 KB |
Output is correct |
38 |
Correct |
14 ms |
63160 KB |
Output is correct |
39 |
Correct |
10 ms |
52056 KB |
Output is correct |
40 |
Correct |
11 ms |
53848 KB |
Output is correct |
41 |
Correct |
10 ms |
52312 KB |
Output is correct |
42 |
Correct |
9 ms |
47960 KB |
Output is correct |
43 |
Correct |
517 ms |
174584 KB |
Output is correct |
44 |
Correct |
741 ms |
208720 KB |
Output is correct |
45 |
Correct |
722 ms |
200248 KB |
Output is correct |
46 |
Correct |
779 ms |
441548 KB |
Output is correct |
47 |
Correct |
824 ms |
441408 KB |
Output is correct |
48 |
Correct |
835 ms |
441420 KB |
Output is correct |
49 |
Correct |
786 ms |
441412 KB |
Output is correct |
50 |
Correct |
830 ms |
441364 KB |
Output is correct |
51 |
Correct |
649 ms |
49752 KB |
Output is correct |
52 |
Correct |
671 ms |
50044 KB |
Output is correct |
53 |
Correct |
612 ms |
48284 KB |
Output is correct |
54 |
Correct |
783 ms |
441320 KB |
Output is correct |
55 |
Correct |
726 ms |
245376 KB |
Output is correct |
56 |
Correct |
689 ms |
147476 KB |
Output is correct |
57 |
Correct |
651 ms |
51372 KB |
Output is correct |
58 |
Correct |
849 ms |
441716 KB |
Output is correct |
59 |
Correct |
790 ms |
441768 KB |
Output is correct |
60 |
Correct |
806 ms |
441724 KB |
Output is correct |
61 |
Correct |
758 ms |
193376 KB |
Output is correct |
62 |
Correct |
718 ms |
166576 KB |
Output is correct |
63 |
Correct |
734 ms |
139916 KB |
Output is correct |
64 |
Correct |
715 ms |
57448 KB |
Output is correct |
65 |
Correct |
378 ms |
113288 KB |
Output is correct |
66 |
Correct |
732 ms |
312496 KB |
Output is correct |
67 |
Correct |
798 ms |
312496 KB |
Output is correct |
68 |
Correct |
804 ms |
312480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
47448 KB |
Output is correct |
2 |
Correct |
7 ms |
47448 KB |
Output is correct |
3 |
Correct |
8 ms |
47448 KB |
Output is correct |
4 |
Correct |
8 ms |
47448 KB |
Output is correct |
5 |
Correct |
7 ms |
47388 KB |
Output is correct |
6 |
Correct |
8 ms |
47448 KB |
Output is correct |
7 |
Correct |
7 ms |
47376 KB |
Output is correct |
8 |
Correct |
8 ms |
47448 KB |
Output is correct |
9 |
Correct |
10 ms |
47448 KB |
Output is correct |
10 |
Correct |
8 ms |
48472 KB |
Output is correct |
11 |
Correct |
9 ms |
51544 KB |
Output is correct |
12 |
Correct |
9 ms |
51544 KB |
Output is correct |
13 |
Correct |
10 ms |
51624 KB |
Output is correct |
14 |
Correct |
11 ms |
55640 KB |
Output is correct |
15 |
Correct |
15 ms |
63064 KB |
Output is correct |
16 |
Correct |
14 ms |
63064 KB |
Output is correct |
17 |
Correct |
15 ms |
62980 KB |
Output is correct |
18 |
Correct |
14 ms |
63064 KB |
Output is correct |
19 |
Correct |
14 ms |
63064 KB |
Output is correct |
20 |
Correct |
12 ms |
58712 KB |
Output is correct |
21 |
Correct |
12 ms |
57944 KB |
Output is correct |
22 |
Correct |
10 ms |
53592 KB |
Output is correct |
23 |
Correct |
10 ms |
53080 KB |
Output is correct |
24 |
Correct |
14 ms |
63064 KB |
Output is correct |
25 |
Correct |
18 ms |
63068 KB |
Output is correct |
26 |
Correct |
14 ms |
63064 KB |
Output is correct |
27 |
Correct |
14 ms |
63064 KB |
Output is correct |
28 |
Correct |
14 ms |
63000 KB |
Output is correct |
29 |
Correct |
8 ms |
47448 KB |
Output is correct |
30 |
Correct |
8 ms |
47448 KB |
Output is correct |
31 |
Correct |
10 ms |
47448 KB |
Output is correct |
32 |
Correct |
14 ms |
63064 KB |
Output is correct |
33 |
Correct |
11 ms |
55128 KB |
Output is correct |
34 |
Correct |
9 ms |
51288 KB |
Output is correct |
35 |
Correct |
8 ms |
47448 KB |
Output is correct |
36 |
Correct |
19 ms |
63064 KB |
Output is correct |
37 |
Correct |
16 ms |
63064 KB |
Output is correct |
38 |
Correct |
14 ms |
63160 KB |
Output is correct |
39 |
Correct |
10 ms |
52056 KB |
Output is correct |
40 |
Correct |
11 ms |
53848 KB |
Output is correct |
41 |
Correct |
10 ms |
52312 KB |
Output is correct |
42 |
Correct |
9 ms |
47960 KB |
Output is correct |
43 |
Runtime error |
743 ms |
2097152 KB |
Execution killed with signal 9 |
44 |
Halted |
0 ms |
0 KB |
- |