#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;
vector<int> g[N], a(N);
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 + n] = A[i];
for (int i = 1; i < n + m; i++) {
g[P[i]].push_back(i);
}
}
pii get(int u) {
if (!sz(g[u])) {
if (a[u]) return {1, 0};
return {0, 1};
}
int cnt = 0;
vector<ll> val(sz(g[u]) + 1);
val[0] = 1;
for (int to: g[u]) {
cnt++;
auto [x, y] = get(to);
for (int i = cnt; i >= 0; i--) {
val[i] = (val[i] * y) % mod;
if (i) val[i] = (val[i] + val[i - 1] * x) % mod;
}
}
ll x = 0, y = 0;
for (int i = 0; i <= cnt; i++) {
x = (x + val[i] * i) % mod;
y = (y + val[i] * (cnt - i)) % mod;
}
return {x, y};
}
int count_ways(int l, int r) {
for (int i = l; i <= r; i++) {
a[i] = 1 - a[i];
}
return get(0).f;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
13912 KB |
Output is correct |
2 |
Correct |
3 ms |
13912 KB |
Output is correct |
3 |
Correct |
10 ms |
14168 KB |
Output is correct |
4 |
Correct |
11 ms |
14164 KB |
Output is correct |
5 |
Correct |
11 ms |
14168 KB |
Output is correct |
6 |
Correct |
11 ms |
14168 KB |
Output is correct |
7 |
Correct |
12 ms |
14168 KB |
Output is correct |
8 |
Correct |
11 ms |
14168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
13912 KB |
Output is correct |
2 |
Correct |
3 ms |
13912 KB |
Output is correct |
3 |
Correct |
3 ms |
13932 KB |
Output is correct |
4 |
Correct |
3 ms |
14168 KB |
Output is correct |
5 |
Correct |
3 ms |
14168 KB |
Output is correct |
6 |
Correct |
3 ms |
14168 KB |
Output is correct |
7 |
Correct |
3 ms |
14168 KB |
Output is correct |
8 |
Correct |
3 ms |
14168 KB |
Output is correct |
9 |
Correct |
3 ms |
14168 KB |
Output is correct |
10 |
Correct |
3 ms |
14168 KB |
Output is correct |
11 |
Correct |
3 ms |
14068 KB |
Output is correct |
12 |
Correct |
4 ms |
14168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
13912 KB |
Output is correct |
2 |
Correct |
3 ms |
13912 KB |
Output is correct |
3 |
Correct |
10 ms |
14168 KB |
Output is correct |
4 |
Correct |
11 ms |
14164 KB |
Output is correct |
5 |
Correct |
11 ms |
14168 KB |
Output is correct |
6 |
Correct |
11 ms |
14168 KB |
Output is correct |
7 |
Correct |
12 ms |
14168 KB |
Output is correct |
8 |
Correct |
11 ms |
14168 KB |
Output is correct |
9 |
Correct |
3 ms |
13912 KB |
Output is correct |
10 |
Correct |
3 ms |
13912 KB |
Output is correct |
11 |
Correct |
3 ms |
13932 KB |
Output is correct |
12 |
Correct |
3 ms |
14168 KB |
Output is correct |
13 |
Correct |
3 ms |
14168 KB |
Output is correct |
14 |
Correct |
3 ms |
14168 KB |
Output is correct |
15 |
Correct |
3 ms |
14168 KB |
Output is correct |
16 |
Correct |
3 ms |
14168 KB |
Output is correct |
17 |
Correct |
3 ms |
14168 KB |
Output is correct |
18 |
Correct |
3 ms |
14168 KB |
Output is correct |
19 |
Correct |
3 ms |
14068 KB |
Output is correct |
20 |
Correct |
4 ms |
14168 KB |
Output is correct |
21 |
Correct |
4 ms |
14332 KB |
Output is correct |
22 |
Correct |
4 ms |
14168 KB |
Output is correct |
23 |
Correct |
3 ms |
14168 KB |
Output is correct |
24 |
Correct |
3 ms |
14168 KB |
Output is correct |
25 |
Correct |
3 ms |
14164 KB |
Output is correct |
26 |
Correct |
4 ms |
14168 KB |
Output is correct |
27 |
Correct |
3 ms |
14168 KB |
Output is correct |
28 |
Correct |
3 ms |
14168 KB |
Output is correct |
29 |
Correct |
11 ms |
14168 KB |
Output is correct |
30 |
Correct |
13 ms |
14168 KB |
Output is correct |
31 |
Correct |
3 ms |
14168 KB |
Output is correct |
32 |
Correct |
3 ms |
14188 KB |
Output is correct |
33 |
Correct |
3 ms |
14168 KB |
Output is correct |
34 |
Correct |
3 ms |
14168 KB |
Output is correct |
35 |
Correct |
5 ms |
13912 KB |
Output is correct |
36 |
Correct |
3 ms |
14168 KB |
Output is correct |
37 |
Correct |
11 ms |
14168 KB |
Output is correct |
38 |
Correct |
11 ms |
14168 KB |
Output is correct |
39 |
Correct |
3 ms |
14168 KB |
Output is correct |
40 |
Correct |
3 ms |
14168 KB |
Output is correct |
41 |
Correct |
3 ms |
14168 KB |
Output is correct |
42 |
Correct |
3 ms |
14168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3072 ms |
15704 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3072 ms |
15704 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
13912 KB |
Output is correct |
2 |
Correct |
3 ms |
13912 KB |
Output is correct |
3 |
Correct |
3 ms |
13932 KB |
Output is correct |
4 |
Correct |
3 ms |
14168 KB |
Output is correct |
5 |
Correct |
3 ms |
14168 KB |
Output is correct |
6 |
Correct |
3 ms |
14168 KB |
Output is correct |
7 |
Correct |
3 ms |
14168 KB |
Output is correct |
8 |
Correct |
3 ms |
14168 KB |
Output is correct |
9 |
Correct |
3 ms |
14168 KB |
Output is correct |
10 |
Correct |
3 ms |
14168 KB |
Output is correct |
11 |
Correct |
3 ms |
14068 KB |
Output is correct |
12 |
Correct |
4 ms |
14168 KB |
Output is correct |
13 |
Execution timed out |
3072 ms |
15704 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
13912 KB |
Output is correct |
2 |
Correct |
3 ms |
13912 KB |
Output is correct |
3 |
Correct |
10 ms |
14168 KB |
Output is correct |
4 |
Correct |
11 ms |
14164 KB |
Output is correct |
5 |
Correct |
11 ms |
14168 KB |
Output is correct |
6 |
Correct |
11 ms |
14168 KB |
Output is correct |
7 |
Correct |
12 ms |
14168 KB |
Output is correct |
8 |
Correct |
11 ms |
14168 KB |
Output is correct |
9 |
Correct |
3 ms |
13912 KB |
Output is correct |
10 |
Correct |
3 ms |
13912 KB |
Output is correct |
11 |
Correct |
3 ms |
13932 KB |
Output is correct |
12 |
Correct |
3 ms |
14168 KB |
Output is correct |
13 |
Correct |
3 ms |
14168 KB |
Output is correct |
14 |
Correct |
3 ms |
14168 KB |
Output is correct |
15 |
Correct |
3 ms |
14168 KB |
Output is correct |
16 |
Correct |
3 ms |
14168 KB |
Output is correct |
17 |
Correct |
3 ms |
14168 KB |
Output is correct |
18 |
Correct |
3 ms |
14168 KB |
Output is correct |
19 |
Correct |
3 ms |
14068 KB |
Output is correct |
20 |
Correct |
4 ms |
14168 KB |
Output is correct |
21 |
Correct |
4 ms |
14332 KB |
Output is correct |
22 |
Correct |
4 ms |
14168 KB |
Output is correct |
23 |
Correct |
3 ms |
14168 KB |
Output is correct |
24 |
Correct |
3 ms |
14168 KB |
Output is correct |
25 |
Correct |
3 ms |
14164 KB |
Output is correct |
26 |
Correct |
4 ms |
14168 KB |
Output is correct |
27 |
Correct |
3 ms |
14168 KB |
Output is correct |
28 |
Correct |
3 ms |
14168 KB |
Output is correct |
29 |
Correct |
11 ms |
14168 KB |
Output is correct |
30 |
Correct |
13 ms |
14168 KB |
Output is correct |
31 |
Correct |
3 ms |
14168 KB |
Output is correct |
32 |
Correct |
3 ms |
14188 KB |
Output is correct |
33 |
Correct |
3 ms |
14168 KB |
Output is correct |
34 |
Correct |
3 ms |
14168 KB |
Output is correct |
35 |
Correct |
5 ms |
13912 KB |
Output is correct |
36 |
Correct |
3 ms |
14168 KB |
Output is correct |
37 |
Correct |
11 ms |
14168 KB |
Output is correct |
38 |
Correct |
11 ms |
14168 KB |
Output is correct |
39 |
Correct |
3 ms |
14168 KB |
Output is correct |
40 |
Correct |
3 ms |
14168 KB |
Output is correct |
41 |
Correct |
3 ms |
14168 KB |
Output is correct |
42 |
Correct |
3 ms |
14168 KB |
Output is correct |
43 |
Execution timed out |
3031 ms |
14168 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
13912 KB |
Output is correct |
2 |
Correct |
3 ms |
13912 KB |
Output is correct |
3 |
Correct |
10 ms |
14168 KB |
Output is correct |
4 |
Correct |
11 ms |
14164 KB |
Output is correct |
5 |
Correct |
11 ms |
14168 KB |
Output is correct |
6 |
Correct |
11 ms |
14168 KB |
Output is correct |
7 |
Correct |
12 ms |
14168 KB |
Output is correct |
8 |
Correct |
11 ms |
14168 KB |
Output is correct |
9 |
Correct |
3 ms |
13912 KB |
Output is correct |
10 |
Correct |
3 ms |
13912 KB |
Output is correct |
11 |
Correct |
3 ms |
13932 KB |
Output is correct |
12 |
Correct |
3 ms |
14168 KB |
Output is correct |
13 |
Correct |
3 ms |
14168 KB |
Output is correct |
14 |
Correct |
3 ms |
14168 KB |
Output is correct |
15 |
Correct |
3 ms |
14168 KB |
Output is correct |
16 |
Correct |
3 ms |
14168 KB |
Output is correct |
17 |
Correct |
3 ms |
14168 KB |
Output is correct |
18 |
Correct |
3 ms |
14168 KB |
Output is correct |
19 |
Correct |
3 ms |
14068 KB |
Output is correct |
20 |
Correct |
4 ms |
14168 KB |
Output is correct |
21 |
Correct |
4 ms |
14332 KB |
Output is correct |
22 |
Correct |
4 ms |
14168 KB |
Output is correct |
23 |
Correct |
3 ms |
14168 KB |
Output is correct |
24 |
Correct |
3 ms |
14168 KB |
Output is correct |
25 |
Correct |
3 ms |
14164 KB |
Output is correct |
26 |
Correct |
4 ms |
14168 KB |
Output is correct |
27 |
Correct |
3 ms |
14168 KB |
Output is correct |
28 |
Correct |
3 ms |
14168 KB |
Output is correct |
29 |
Correct |
11 ms |
14168 KB |
Output is correct |
30 |
Correct |
13 ms |
14168 KB |
Output is correct |
31 |
Correct |
3 ms |
14168 KB |
Output is correct |
32 |
Correct |
3 ms |
14188 KB |
Output is correct |
33 |
Correct |
3 ms |
14168 KB |
Output is correct |
34 |
Correct |
3 ms |
14168 KB |
Output is correct |
35 |
Correct |
5 ms |
13912 KB |
Output is correct |
36 |
Correct |
3 ms |
14168 KB |
Output is correct |
37 |
Correct |
11 ms |
14168 KB |
Output is correct |
38 |
Correct |
11 ms |
14168 KB |
Output is correct |
39 |
Correct |
3 ms |
14168 KB |
Output is correct |
40 |
Correct |
3 ms |
14168 KB |
Output is correct |
41 |
Correct |
3 ms |
14168 KB |
Output is correct |
42 |
Correct |
3 ms |
14168 KB |
Output is correct |
43 |
Execution timed out |
3072 ms |
15704 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |