#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 200005;
const int MOD = 1e9 + 2022;
using ll = long long;
int N, M;
vector<int> g[MaxN];
ll dp[MaxN][2];
vector<int> A;
void dfs(int v){
if (v >= N){
int st = A[v - N];
dp[v][st] = 1;
dp[v][!st] = 0;
return;
}
int c = (int) g[v].size();
for (int u : g[v]){
dfs(u);
}
vector<ll> knapsack(c + 1, 0);
knapsack[0] = 1;
dp[v][0] = 0;
dp[v][1] = 0;
long long tot = c;
for (int u : g[v]){
tot = tot * (dp[u][0] + dp[u][1]) % MOD;
for (int i = c; i >= 0; i--){
long long x = knapsack[i] * dp[u][0];
if (i > 0) x += knapsack[i - 1] * dp[u][1];
knapsack[i] = x % MOD;
}
}
for (int i = 1; i <= c; i++){
dp[v][1] += knapsack[i] * i;
dp[v][1] %= MOD;
}
dp[v][0] = tot - dp[v][1];
if (dp[v][0] < 0) dp[v][0] += MOD;
}
void init(int _N, int _M, vector<int> P, vector<int> _A) {
N = _N, M = _M, A = _A;
for (int i = 1; i < N + M; i++){
g[P[i]].push_back(i);
}
}
int count_ways(int L, int R) {
for (int i = L; i <= R; i++){
A[i - N] ^= 1;
}
dfs(0);
return dp[0][1];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
11 ms |
5048 KB |
Output is correct |
4 |
Correct |
13 ms |
5044 KB |
Output is correct |
5 |
Correct |
10 ms |
5040 KB |
Output is correct |
6 |
Correct |
10 ms |
4944 KB |
Output is correct |
7 |
Correct |
16 ms |
4944 KB |
Output is correct |
8 |
Correct |
10 ms |
4944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 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 |
3 ms |
5072 KB |
Output is correct |
11 |
Correct |
4 ms |
5072 KB |
Output is correct |
12 |
Correct |
3 ms |
4944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
11 ms |
5048 KB |
Output is correct |
4 |
Correct |
13 ms |
5044 KB |
Output is correct |
5 |
Correct |
10 ms |
5040 KB |
Output is correct |
6 |
Correct |
10 ms |
4944 KB |
Output is correct |
7 |
Correct |
16 ms |
4944 KB |
Output is correct |
8 |
Correct |
10 ms |
4944 KB |
Output is correct |
9 |
Correct |
2 ms |
4944 KB |
Output is correct |
10 |
Correct |
2 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 |
3 ms |
5072 KB |
Output is correct |
19 |
Correct |
4 ms |
5072 KB |
Output is correct |
20 |
Correct |
3 ms |
4944 KB |
Output is correct |
21 |
Correct |
2 ms |
5072 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 |
3 ms |
5072 KB |
Output is correct |
27 |
Correct |
4 ms |
5072 KB |
Output is correct |
28 |
Correct |
3 ms |
5072 KB |
Output is correct |
29 |
Correct |
9 ms |
4944 KB |
Output is correct |
30 |
Correct |
11 ms |
4944 KB |
Output is correct |
31 |
Correct |
2 ms |
5072 KB |
Output is correct |
32 |
Correct |
4 ms |
5072 KB |
Output is correct |
33 |
Correct |
3 ms |
4944 KB |
Output is correct |
34 |
Correct |
3 ms |
4944 KB |
Output is correct |
35 |
Correct |
4 ms |
4944 KB |
Output is correct |
36 |
Correct |
3 ms |
5072 KB |
Output is correct |
37 |
Correct |
10 ms |
5168 KB |
Output is correct |
38 |
Correct |
10 ms |
5188 KB |
Output is correct |
39 |
Correct |
2 ms |
4944 KB |
Output is correct |
40 |
Correct |
3 ms |
4944 KB |
Output is correct |
41 |
Correct |
3 ms |
4956 KB |
Output is correct |
42 |
Correct |
3 ms |
4944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3091 ms |
7556 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3091 ms |
7556 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 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 |
3 ms |
5072 KB |
Output is correct |
11 |
Correct |
4 ms |
5072 KB |
Output is correct |
12 |
Correct |
3 ms |
4944 KB |
Output is correct |
13 |
Execution timed out |
3091 ms |
7556 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
11 ms |
5048 KB |
Output is correct |
4 |
Correct |
13 ms |
5044 KB |
Output is correct |
5 |
Correct |
10 ms |
5040 KB |
Output is correct |
6 |
Correct |
10 ms |
4944 KB |
Output is correct |
7 |
Correct |
16 ms |
4944 KB |
Output is correct |
8 |
Correct |
10 ms |
4944 KB |
Output is correct |
9 |
Correct |
2 ms |
4944 KB |
Output is correct |
10 |
Correct |
2 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 |
3 ms |
5072 KB |
Output is correct |
19 |
Correct |
4 ms |
5072 KB |
Output is correct |
20 |
Correct |
3 ms |
4944 KB |
Output is correct |
21 |
Correct |
2 ms |
5072 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 |
3 ms |
5072 KB |
Output is correct |
27 |
Correct |
4 ms |
5072 KB |
Output is correct |
28 |
Correct |
3 ms |
5072 KB |
Output is correct |
29 |
Correct |
9 ms |
4944 KB |
Output is correct |
30 |
Correct |
11 ms |
4944 KB |
Output is correct |
31 |
Correct |
2 ms |
5072 KB |
Output is correct |
32 |
Correct |
4 ms |
5072 KB |
Output is correct |
33 |
Correct |
3 ms |
4944 KB |
Output is correct |
34 |
Correct |
3 ms |
4944 KB |
Output is correct |
35 |
Correct |
4 ms |
4944 KB |
Output is correct |
36 |
Correct |
3 ms |
5072 KB |
Output is correct |
37 |
Correct |
10 ms |
5168 KB |
Output is correct |
38 |
Correct |
10 ms |
5188 KB |
Output is correct |
39 |
Correct |
2 ms |
4944 KB |
Output is correct |
40 |
Correct |
3 ms |
4944 KB |
Output is correct |
41 |
Correct |
3 ms |
4956 KB |
Output is correct |
42 |
Correct |
3 ms |
4944 KB |
Output is correct |
43 |
Execution timed out |
3004 ms |
5232 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
11 ms |
5048 KB |
Output is correct |
4 |
Correct |
13 ms |
5044 KB |
Output is correct |
5 |
Correct |
10 ms |
5040 KB |
Output is correct |
6 |
Correct |
10 ms |
4944 KB |
Output is correct |
7 |
Correct |
16 ms |
4944 KB |
Output is correct |
8 |
Correct |
10 ms |
4944 KB |
Output is correct |
9 |
Correct |
2 ms |
4944 KB |
Output is correct |
10 |
Correct |
2 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 |
3 ms |
5072 KB |
Output is correct |
19 |
Correct |
4 ms |
5072 KB |
Output is correct |
20 |
Correct |
3 ms |
4944 KB |
Output is correct |
21 |
Correct |
2 ms |
5072 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 |
3 ms |
5072 KB |
Output is correct |
27 |
Correct |
4 ms |
5072 KB |
Output is correct |
28 |
Correct |
3 ms |
5072 KB |
Output is correct |
29 |
Correct |
9 ms |
4944 KB |
Output is correct |
30 |
Correct |
11 ms |
4944 KB |
Output is correct |
31 |
Correct |
2 ms |
5072 KB |
Output is correct |
32 |
Correct |
4 ms |
5072 KB |
Output is correct |
33 |
Correct |
3 ms |
4944 KB |
Output is correct |
34 |
Correct |
3 ms |
4944 KB |
Output is correct |
35 |
Correct |
4 ms |
4944 KB |
Output is correct |
36 |
Correct |
3 ms |
5072 KB |
Output is correct |
37 |
Correct |
10 ms |
5168 KB |
Output is correct |
38 |
Correct |
10 ms |
5188 KB |
Output is correct |
39 |
Correct |
2 ms |
4944 KB |
Output is correct |
40 |
Correct |
3 ms |
4944 KB |
Output is correct |
41 |
Correct |
3 ms |
4956 KB |
Output is correct |
42 |
Correct |
3 ms |
4944 KB |
Output is correct |
43 |
Execution timed out |
3091 ms |
7556 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |