#include "circuit.h"
#include <bits/stdc++.h>
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define rf(i, a, b) for(int i = a; i >= b; i--)
#define fe(x, y) for (auto& x : y)
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define pw(x) (1LL << (x))
#define sz(x) (int)x.size()
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define fbo find_by_order
#define ook order_of_key
template <typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ve = vector <T>;
template <typename T>
bool umx (T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T>
bool umn (T& a, T b) { return a > b ? a = b, 1 : 0; }
using ll = long long;
using ld = long double;
using pll = pair <ll, ll>;
using pii = pair <int, int>;
using ull = unsigned long long;
const int oo = 1e9;
const ll OO = 1e18;
const int N = 2e5 + 10;
const int M = 5e3 + 100;
const int mod = 1e9 + 2022;
int a[N];
int dp[N][2];
int n, m;
int add(int a, int b) {
return a + b < mod ? a + b : a + b - mod;
}
int mul (int a, int b) {
return 1LL * a * b % mod;
}
ve <int> G[N];
void calc(int u) {
if (!sz(G[u])) {
if(a[u]) {
dp[u][0] = 0;
dp[u][1] = 1;
} else {
dp[u][0] = 1;
dp[u][1] = 0;
}
return;
}
for (auto to : G[u]) calc(to);
ve <ve <int>> d(sz(G[u]) + 1);
fe (x, d) x.resize(sz(G[u]) + 1);
d[0][0] = 1;
for (int i = 0; i < sz(G[u]); i++) {
int to = G[u][i];
for (int cnt_al = 0; cnt_al <= i; cnt_al++) {
d[i + 1][cnt_al + 1] = add(d[i + 1][cnt_al + 1], mul(d[i][cnt_al], dp[to][1]));
d[i + 1][cnt_al] = add(d[i + 1][cnt_al], mul(d[i][cnt_al], dp[to][0]));
}
}
dp[u][0] = dp[u][1] = 0;
for (int cnt_al = 0; cnt_al <= sz(G[u]); cnt_al++) {
dp[u][1] = add(dp[u][1], mul(d[sz(G[u])][cnt_al], max(0, cnt_al)));
dp[u][0] = add(dp[u][0], mul(d[sz(G[u])][cnt_al], sz(G[u]) - cnt_al));
}
}
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
n = N;
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]].pb(i);
}
int count_ways(int L, int R) {
for (int i = L; i <= R; i++) a[i] = 1 - a[i];
calc(0);
return dp[0][1];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
18 ms |
8772 KB |
Output is correct |
4 |
Correct |
19 ms |
9000 KB |
Output is correct |
5 |
Correct |
19 ms |
8944 KB |
Output is correct |
6 |
Correct |
27 ms |
8988 KB |
Output is correct |
7 |
Correct |
17 ms |
8980 KB |
Output is correct |
8 |
Correct |
18 ms |
9000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4888 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
4944 KB |
Output is correct |
4 |
Correct |
3 ms |
4944 KB |
Output is correct |
5 |
Correct |
3 ms |
4944 KB |
Output is correct |
6 |
Correct |
3 ms |
4944 KB |
Output is correct |
7 |
Correct |
3 ms |
5072 KB |
Output is correct |
8 |
Correct |
3 ms |
5072 KB |
Output is correct |
9 |
Correct |
3 ms |
5072 KB |
Output is correct |
10 |
Correct |
4 ms |
5072 KB |
Output is correct |
11 |
Correct |
3 ms |
5072 KB |
Output is correct |
12 |
Correct |
4 ms |
4944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
18 ms |
8772 KB |
Output is correct |
4 |
Correct |
19 ms |
9000 KB |
Output is correct |
5 |
Correct |
19 ms |
8944 KB |
Output is correct |
6 |
Correct |
27 ms |
8988 KB |
Output is correct |
7 |
Correct |
17 ms |
8980 KB |
Output is correct |
8 |
Correct |
18 ms |
9000 KB |
Output is correct |
9 |
Correct |
2 ms |
4888 KB |
Output is correct |
10 |
Correct |
3 ms |
4944 KB |
Output is correct |
11 |
Correct |
3 ms |
4944 KB |
Output is correct |
12 |
Correct |
3 ms |
4944 KB |
Output is correct |
13 |
Correct |
3 ms |
4944 KB |
Output is correct |
14 |
Correct |
3 ms |
4944 KB |
Output is correct |
15 |
Correct |
3 ms |
5072 KB |
Output is correct |
16 |
Correct |
3 ms |
5072 KB |
Output is correct |
17 |
Correct |
3 ms |
5072 KB |
Output is correct |
18 |
Correct |
4 ms |
5072 KB |
Output is correct |
19 |
Correct |
3 ms |
5072 KB |
Output is correct |
20 |
Correct |
4 ms |
4944 KB |
Output is correct |
21 |
Correct |
3 ms |
4944 KB |
Output is correct |
22 |
Correct |
3 ms |
4944 KB |
Output is correct |
23 |
Correct |
3 ms |
4944 KB |
Output is correct |
24 |
Correct |
3 ms |
5072 KB |
Output is correct |
25 |
Correct |
3 ms |
5072 KB |
Output is correct |
26 |
Correct |
4 ms |
5072 KB |
Output is correct |
27 |
Correct |
3 ms |
5072 KB |
Output is correct |
28 |
Correct |
3 ms |
5072 KB |
Output is correct |
29 |
Correct |
21 ms |
8928 KB |
Output is correct |
30 |
Correct |
18 ms |
8980 KB |
Output is correct |
31 |
Correct |
4 ms |
5072 KB |
Output is correct |
32 |
Correct |
7 ms |
5084 KB |
Output is correct |
33 |
Correct |
3 ms |
4944 KB |
Output is correct |
34 |
Correct |
3 ms |
4944 KB |
Output is correct |
35 |
Correct |
6 ms |
5244 KB |
Output is correct |
36 |
Correct |
4 ms |
5072 KB |
Output is correct |
37 |
Correct |
18 ms |
9140 KB |
Output is correct |
38 |
Correct |
18 ms |
9104 KB |
Output is correct |
39 |
Correct |
3 ms |
4944 KB |
Output is correct |
40 |
Correct |
3 ms |
4944 KB |
Output is correct |
41 |
Correct |
5 ms |
4944 KB |
Output is correct |
42 |
Correct |
5 ms |
5080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3076 ms |
6976 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3076 ms |
6976 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4888 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
4944 KB |
Output is correct |
4 |
Correct |
3 ms |
4944 KB |
Output is correct |
5 |
Correct |
3 ms |
4944 KB |
Output is correct |
6 |
Correct |
3 ms |
4944 KB |
Output is correct |
7 |
Correct |
3 ms |
5072 KB |
Output is correct |
8 |
Correct |
3 ms |
5072 KB |
Output is correct |
9 |
Correct |
3 ms |
5072 KB |
Output is correct |
10 |
Correct |
4 ms |
5072 KB |
Output is correct |
11 |
Correct |
3 ms |
5072 KB |
Output is correct |
12 |
Correct |
4 ms |
4944 KB |
Output is correct |
13 |
Execution timed out |
3076 ms |
6976 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
18 ms |
8772 KB |
Output is correct |
4 |
Correct |
19 ms |
9000 KB |
Output is correct |
5 |
Correct |
19 ms |
8944 KB |
Output is correct |
6 |
Correct |
27 ms |
8988 KB |
Output is correct |
7 |
Correct |
17 ms |
8980 KB |
Output is correct |
8 |
Correct |
18 ms |
9000 KB |
Output is correct |
9 |
Correct |
2 ms |
4888 KB |
Output is correct |
10 |
Correct |
3 ms |
4944 KB |
Output is correct |
11 |
Correct |
3 ms |
4944 KB |
Output is correct |
12 |
Correct |
3 ms |
4944 KB |
Output is correct |
13 |
Correct |
3 ms |
4944 KB |
Output is correct |
14 |
Correct |
3 ms |
4944 KB |
Output is correct |
15 |
Correct |
3 ms |
5072 KB |
Output is correct |
16 |
Correct |
3 ms |
5072 KB |
Output is correct |
17 |
Correct |
3 ms |
5072 KB |
Output is correct |
18 |
Correct |
4 ms |
5072 KB |
Output is correct |
19 |
Correct |
3 ms |
5072 KB |
Output is correct |
20 |
Correct |
4 ms |
4944 KB |
Output is correct |
21 |
Correct |
3 ms |
4944 KB |
Output is correct |
22 |
Correct |
3 ms |
4944 KB |
Output is correct |
23 |
Correct |
3 ms |
4944 KB |
Output is correct |
24 |
Correct |
3 ms |
5072 KB |
Output is correct |
25 |
Correct |
3 ms |
5072 KB |
Output is correct |
26 |
Correct |
4 ms |
5072 KB |
Output is correct |
27 |
Correct |
3 ms |
5072 KB |
Output is correct |
28 |
Correct |
3 ms |
5072 KB |
Output is correct |
29 |
Correct |
21 ms |
8928 KB |
Output is correct |
30 |
Correct |
18 ms |
8980 KB |
Output is correct |
31 |
Correct |
4 ms |
5072 KB |
Output is correct |
32 |
Correct |
7 ms |
5084 KB |
Output is correct |
33 |
Correct |
3 ms |
4944 KB |
Output is correct |
34 |
Correct |
3 ms |
4944 KB |
Output is correct |
35 |
Correct |
6 ms |
5244 KB |
Output is correct |
36 |
Correct |
4 ms |
5072 KB |
Output is correct |
37 |
Correct |
18 ms |
9140 KB |
Output is correct |
38 |
Correct |
18 ms |
9104 KB |
Output is correct |
39 |
Correct |
3 ms |
4944 KB |
Output is correct |
40 |
Correct |
3 ms |
4944 KB |
Output is correct |
41 |
Correct |
5 ms |
4944 KB |
Output is correct |
42 |
Correct |
5 ms |
5080 KB |
Output is correct |
43 |
Execution timed out |
3045 ms |
5200 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
18 ms |
8772 KB |
Output is correct |
4 |
Correct |
19 ms |
9000 KB |
Output is correct |
5 |
Correct |
19 ms |
8944 KB |
Output is correct |
6 |
Correct |
27 ms |
8988 KB |
Output is correct |
7 |
Correct |
17 ms |
8980 KB |
Output is correct |
8 |
Correct |
18 ms |
9000 KB |
Output is correct |
9 |
Correct |
2 ms |
4888 KB |
Output is correct |
10 |
Correct |
3 ms |
4944 KB |
Output is correct |
11 |
Correct |
3 ms |
4944 KB |
Output is correct |
12 |
Correct |
3 ms |
4944 KB |
Output is correct |
13 |
Correct |
3 ms |
4944 KB |
Output is correct |
14 |
Correct |
3 ms |
4944 KB |
Output is correct |
15 |
Correct |
3 ms |
5072 KB |
Output is correct |
16 |
Correct |
3 ms |
5072 KB |
Output is correct |
17 |
Correct |
3 ms |
5072 KB |
Output is correct |
18 |
Correct |
4 ms |
5072 KB |
Output is correct |
19 |
Correct |
3 ms |
5072 KB |
Output is correct |
20 |
Correct |
4 ms |
4944 KB |
Output is correct |
21 |
Correct |
3 ms |
4944 KB |
Output is correct |
22 |
Correct |
3 ms |
4944 KB |
Output is correct |
23 |
Correct |
3 ms |
4944 KB |
Output is correct |
24 |
Correct |
3 ms |
5072 KB |
Output is correct |
25 |
Correct |
3 ms |
5072 KB |
Output is correct |
26 |
Correct |
4 ms |
5072 KB |
Output is correct |
27 |
Correct |
3 ms |
5072 KB |
Output is correct |
28 |
Correct |
3 ms |
5072 KB |
Output is correct |
29 |
Correct |
21 ms |
8928 KB |
Output is correct |
30 |
Correct |
18 ms |
8980 KB |
Output is correct |
31 |
Correct |
4 ms |
5072 KB |
Output is correct |
32 |
Correct |
7 ms |
5084 KB |
Output is correct |
33 |
Correct |
3 ms |
4944 KB |
Output is correct |
34 |
Correct |
3 ms |
4944 KB |
Output is correct |
35 |
Correct |
6 ms |
5244 KB |
Output is correct |
36 |
Correct |
4 ms |
5072 KB |
Output is correct |
37 |
Correct |
18 ms |
9140 KB |
Output is correct |
38 |
Correct |
18 ms |
9104 KB |
Output is correct |
39 |
Correct |
3 ms |
4944 KB |
Output is correct |
40 |
Correct |
3 ms |
4944 KB |
Output is correct |
41 |
Correct |
5 ms |
4944 KB |
Output is correct |
42 |
Correct |
5 ms |
5080 KB |
Output is correct |
43 |
Execution timed out |
3076 ms |
6976 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |