#include "circuit.h"
#ifdef NYAOWO
#include "stub.cpp"
#endif
#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define eb emplace_back
#define int LL
using namespace std;
using i32 = int32_t;
using LL = long long;
using pii = pair<int, int>;
const int MAXN = 100'000;
const int MOD = 1'000'002'022;
int n, m;
vector<int> adj[MAXN + 10];
int dp[MAXN + 10][2];
void update(int x) {
vector<int> v(1, 1);
for(auto &child:adj[x]) {
vector<int> v2;
v2.eb(v[0] * dp[child][0] % MOD);
For(i, 1, sz(v) - 1) {
v2.eb((v[i] * dp[child][0] + v[i - 1] * dp[child][1]) % MOD);
}
v2.eb(v.back() * dp[child][1] % MOD);
v.swap(v2);
}
dp[x][0] = dp[x][1] = 0;
int c = sz(adj[x]);
For(i, 0, c) {
dp[x][0] = (dp[x][0] + v[i] * (c - i)) % MOD;
dp[x][1] = (dp[x][1] + v[i] * i) % MOD;
}
}
void init(i32 N, i32 M, std::vector<i32> P, std::vector<i32> A) {
n = N; m = M;
For(i, 1, n + m - 1) {
adj[P[i]].eb(i);
}
For(i, 0, m - 1) {
int x = A[i];
dp[n + i][x] = 1;
dp[n + i][1 - x] = 0;
}
}
i32 count_ways(i32 L, i32 R) {
For(i, L, R) swap(dp[i][0], dp[i][1]);
Forr(i, n - 1, 0) update(i);
return (i32)dp[0][1];
}
/*
3 4 3
-1 0 1 2 1 1 0
1 0 1 0
3 4
4 5
3 6
2
0
6
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Correct |
9 ms |
2640 KB |
Output is correct |
4 |
Correct |
9 ms |
2712 KB |
Output is correct |
5 |
Correct |
9 ms |
2712 KB |
Output is correct |
6 |
Correct |
9 ms |
2640 KB |
Output is correct |
7 |
Correct |
9 ms |
2640 KB |
Output is correct |
8 |
Correct |
9 ms |
2768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2640 KB |
Output is correct |
4 |
Correct |
2 ms |
2640 KB |
Output is correct |
5 |
Correct |
2 ms |
2640 KB |
Output is correct |
6 |
Correct |
2 ms |
2640 KB |
Output is correct |
7 |
Correct |
2 ms |
2640 KB |
Output is correct |
8 |
Correct |
2 ms |
2640 KB |
Output is correct |
9 |
Correct |
2 ms |
2640 KB |
Output is correct |
10 |
Correct |
2 ms |
2640 KB |
Output is correct |
11 |
Correct |
2 ms |
2640 KB |
Output is correct |
12 |
Correct |
2 ms |
2640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Correct |
9 ms |
2640 KB |
Output is correct |
4 |
Correct |
9 ms |
2712 KB |
Output is correct |
5 |
Correct |
9 ms |
2712 KB |
Output is correct |
6 |
Correct |
9 ms |
2640 KB |
Output is correct |
7 |
Correct |
9 ms |
2640 KB |
Output is correct |
8 |
Correct |
9 ms |
2768 KB |
Output is correct |
9 |
Correct |
1 ms |
2640 KB |
Output is correct |
10 |
Correct |
1 ms |
2640 KB |
Output is correct |
11 |
Correct |
2 ms |
2640 KB |
Output is correct |
12 |
Correct |
2 ms |
2640 KB |
Output is correct |
13 |
Correct |
2 ms |
2640 KB |
Output is correct |
14 |
Correct |
2 ms |
2640 KB |
Output is correct |
15 |
Correct |
2 ms |
2640 KB |
Output is correct |
16 |
Correct |
2 ms |
2640 KB |
Output is correct |
17 |
Correct |
2 ms |
2640 KB |
Output is correct |
18 |
Correct |
2 ms |
2640 KB |
Output is correct |
19 |
Correct |
2 ms |
2640 KB |
Output is correct |
20 |
Correct |
2 ms |
2640 KB |
Output is correct |
21 |
Correct |
2 ms |
2640 KB |
Output is correct |
22 |
Correct |
2 ms |
2640 KB |
Output is correct |
23 |
Correct |
2 ms |
2640 KB |
Output is correct |
24 |
Correct |
2 ms |
2640 KB |
Output is correct |
25 |
Correct |
2 ms |
2640 KB |
Output is correct |
26 |
Correct |
4 ms |
2640 KB |
Output is correct |
27 |
Correct |
2 ms |
2640 KB |
Output is correct |
28 |
Correct |
2 ms |
2640 KB |
Output is correct |
29 |
Correct |
9 ms |
2640 KB |
Output is correct |
30 |
Correct |
9 ms |
2720 KB |
Output is correct |
31 |
Correct |
2 ms |
2640 KB |
Output is correct |
32 |
Correct |
2 ms |
2640 KB |
Output is correct |
33 |
Correct |
2 ms |
2640 KB |
Output is correct |
34 |
Correct |
2 ms |
2640 KB |
Output is correct |
35 |
Correct |
3 ms |
2640 KB |
Output is correct |
36 |
Correct |
2 ms |
2640 KB |
Output is correct |
37 |
Correct |
9 ms |
2768 KB |
Output is correct |
38 |
Correct |
10 ms |
2768 KB |
Output is correct |
39 |
Correct |
2 ms |
2640 KB |
Output is correct |
40 |
Correct |
2 ms |
2640 KB |
Output is correct |
41 |
Correct |
2 ms |
2640 KB |
Output is correct |
42 |
Correct |
2 ms |
2640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3096 ms |
5100 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3096 ms |
5100 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2640 KB |
Output is correct |
4 |
Correct |
2 ms |
2640 KB |
Output is correct |
5 |
Correct |
2 ms |
2640 KB |
Output is correct |
6 |
Correct |
2 ms |
2640 KB |
Output is correct |
7 |
Correct |
2 ms |
2640 KB |
Output is correct |
8 |
Correct |
2 ms |
2640 KB |
Output is correct |
9 |
Correct |
2 ms |
2640 KB |
Output is correct |
10 |
Correct |
2 ms |
2640 KB |
Output is correct |
11 |
Correct |
2 ms |
2640 KB |
Output is correct |
12 |
Correct |
2 ms |
2640 KB |
Output is correct |
13 |
Execution timed out |
3096 ms |
5100 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Correct |
9 ms |
2640 KB |
Output is correct |
4 |
Correct |
9 ms |
2712 KB |
Output is correct |
5 |
Correct |
9 ms |
2712 KB |
Output is correct |
6 |
Correct |
9 ms |
2640 KB |
Output is correct |
7 |
Correct |
9 ms |
2640 KB |
Output is correct |
8 |
Correct |
9 ms |
2768 KB |
Output is correct |
9 |
Correct |
1 ms |
2640 KB |
Output is correct |
10 |
Correct |
1 ms |
2640 KB |
Output is correct |
11 |
Correct |
2 ms |
2640 KB |
Output is correct |
12 |
Correct |
2 ms |
2640 KB |
Output is correct |
13 |
Correct |
2 ms |
2640 KB |
Output is correct |
14 |
Correct |
2 ms |
2640 KB |
Output is correct |
15 |
Correct |
2 ms |
2640 KB |
Output is correct |
16 |
Correct |
2 ms |
2640 KB |
Output is correct |
17 |
Correct |
2 ms |
2640 KB |
Output is correct |
18 |
Correct |
2 ms |
2640 KB |
Output is correct |
19 |
Correct |
2 ms |
2640 KB |
Output is correct |
20 |
Correct |
2 ms |
2640 KB |
Output is correct |
21 |
Correct |
2 ms |
2640 KB |
Output is correct |
22 |
Correct |
2 ms |
2640 KB |
Output is correct |
23 |
Correct |
2 ms |
2640 KB |
Output is correct |
24 |
Correct |
2 ms |
2640 KB |
Output is correct |
25 |
Correct |
2 ms |
2640 KB |
Output is correct |
26 |
Correct |
4 ms |
2640 KB |
Output is correct |
27 |
Correct |
2 ms |
2640 KB |
Output is correct |
28 |
Correct |
2 ms |
2640 KB |
Output is correct |
29 |
Correct |
9 ms |
2640 KB |
Output is correct |
30 |
Correct |
9 ms |
2720 KB |
Output is correct |
31 |
Correct |
2 ms |
2640 KB |
Output is correct |
32 |
Correct |
2 ms |
2640 KB |
Output is correct |
33 |
Correct |
2 ms |
2640 KB |
Output is correct |
34 |
Correct |
2 ms |
2640 KB |
Output is correct |
35 |
Correct |
3 ms |
2640 KB |
Output is correct |
36 |
Correct |
2 ms |
2640 KB |
Output is correct |
37 |
Correct |
9 ms |
2768 KB |
Output is correct |
38 |
Correct |
10 ms |
2768 KB |
Output is correct |
39 |
Correct |
2 ms |
2640 KB |
Output is correct |
40 |
Correct |
2 ms |
2640 KB |
Output is correct |
41 |
Correct |
2 ms |
2640 KB |
Output is correct |
42 |
Correct |
2 ms |
2640 KB |
Output is correct |
43 |
Execution timed out |
3090 ms |
2896 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Correct |
9 ms |
2640 KB |
Output is correct |
4 |
Correct |
9 ms |
2712 KB |
Output is correct |
5 |
Correct |
9 ms |
2712 KB |
Output is correct |
6 |
Correct |
9 ms |
2640 KB |
Output is correct |
7 |
Correct |
9 ms |
2640 KB |
Output is correct |
8 |
Correct |
9 ms |
2768 KB |
Output is correct |
9 |
Correct |
1 ms |
2640 KB |
Output is correct |
10 |
Correct |
1 ms |
2640 KB |
Output is correct |
11 |
Correct |
2 ms |
2640 KB |
Output is correct |
12 |
Correct |
2 ms |
2640 KB |
Output is correct |
13 |
Correct |
2 ms |
2640 KB |
Output is correct |
14 |
Correct |
2 ms |
2640 KB |
Output is correct |
15 |
Correct |
2 ms |
2640 KB |
Output is correct |
16 |
Correct |
2 ms |
2640 KB |
Output is correct |
17 |
Correct |
2 ms |
2640 KB |
Output is correct |
18 |
Correct |
2 ms |
2640 KB |
Output is correct |
19 |
Correct |
2 ms |
2640 KB |
Output is correct |
20 |
Correct |
2 ms |
2640 KB |
Output is correct |
21 |
Correct |
2 ms |
2640 KB |
Output is correct |
22 |
Correct |
2 ms |
2640 KB |
Output is correct |
23 |
Correct |
2 ms |
2640 KB |
Output is correct |
24 |
Correct |
2 ms |
2640 KB |
Output is correct |
25 |
Correct |
2 ms |
2640 KB |
Output is correct |
26 |
Correct |
4 ms |
2640 KB |
Output is correct |
27 |
Correct |
2 ms |
2640 KB |
Output is correct |
28 |
Correct |
2 ms |
2640 KB |
Output is correct |
29 |
Correct |
9 ms |
2640 KB |
Output is correct |
30 |
Correct |
9 ms |
2720 KB |
Output is correct |
31 |
Correct |
2 ms |
2640 KB |
Output is correct |
32 |
Correct |
2 ms |
2640 KB |
Output is correct |
33 |
Correct |
2 ms |
2640 KB |
Output is correct |
34 |
Correct |
2 ms |
2640 KB |
Output is correct |
35 |
Correct |
3 ms |
2640 KB |
Output is correct |
36 |
Correct |
2 ms |
2640 KB |
Output is correct |
37 |
Correct |
9 ms |
2768 KB |
Output is correct |
38 |
Correct |
10 ms |
2768 KB |
Output is correct |
39 |
Correct |
2 ms |
2640 KB |
Output is correct |
40 |
Correct |
2 ms |
2640 KB |
Output is correct |
41 |
Correct |
2 ms |
2640 KB |
Output is correct |
42 |
Correct |
2 ms |
2640 KB |
Output is correct |
43 |
Execution timed out |
3096 ms |
5100 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |