#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2e5;
const int MAX_M = 1e5;
const int MOD = 1e9 + 2022;
int dp1[MAX_N], dpTot[MAX_N];
vector<int> adj[MAX_N];
int n, m;
void dfs( int u ) {
for ( int v: adj[u] )
dfs( v );
dpTot[u] = 1;
dp1[u] = (u >= n - m ? dp1[u] : 0);
for ( int v: adj[u] ) {
dp1[u] = ((long long)dp1[u] * (dpTot[v] - dp1[v] + MOD) % MOD + (long long)(dp1[u] + dpTot[u]) * dp1[v] % MOD) % MOD;
dpTot[u] = (long long)dpTot[u] * dpTot[v] % MOD;
//printf( "fii %d %d %d %d\n", u, v, dpTot[u], dp1[u] );
}
dpTot[u] = (long long)dpTot[u] * max( 1, (int)adj[u].size() ) % MOD;
//printf( "%d %d %d\n", u, dpTot[u], dp1[u] );
}
void init( int N, int M, vector<int> P, vector<int> A ) {
n = N + M, m = M;
for ( int v = 1; v < n; v++ )
adj[P[v]].push_back( v );
for ( int v = 0; v < m; v++ )
dp1[v + n - m] = A[v];
}
int count_ways( int L, int R ) {
for ( int i = L; i <= R; i++ )
dp1[i] = !dp1[i];
dfs( 0 );
return dp1[0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4952 KB |
Output is correct |
2 |
Correct |
1 ms |
4952 KB |
Output is correct |
3 |
Correct |
2 ms |
5096 KB |
Output is correct |
4 |
Correct |
2 ms |
4952 KB |
Output is correct |
5 |
Correct |
2 ms |
4952 KB |
Output is correct |
6 |
Correct |
2 ms |
4952 KB |
Output is correct |
7 |
Correct |
2 ms |
4952 KB |
Output is correct |
8 |
Correct |
2 ms |
4952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
1 ms |
4952 KB |
Output is correct |
3 |
Correct |
1 ms |
4952 KB |
Output is correct |
4 |
Correct |
1 ms |
4952 KB |
Output is correct |
5 |
Correct |
1 ms |
4952 KB |
Output is correct |
6 |
Correct |
2 ms |
5040 KB |
Output is correct |
7 |
Correct |
2 ms |
5208 KB |
Output is correct |
8 |
Correct |
2 ms |
5208 KB |
Output is correct |
9 |
Correct |
2 ms |
5208 KB |
Output is correct |
10 |
Correct |
2 ms |
5460 KB |
Output is correct |
11 |
Correct |
2 ms |
5208 KB |
Output is correct |
12 |
Correct |
2 ms |
4952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4952 KB |
Output is correct |
2 |
Correct |
1 ms |
4952 KB |
Output is correct |
3 |
Correct |
2 ms |
5096 KB |
Output is correct |
4 |
Correct |
2 ms |
4952 KB |
Output is correct |
5 |
Correct |
2 ms |
4952 KB |
Output is correct |
6 |
Correct |
2 ms |
4952 KB |
Output is correct |
7 |
Correct |
2 ms |
4952 KB |
Output is correct |
8 |
Correct |
2 ms |
4952 KB |
Output is correct |
9 |
Correct |
2 ms |
4952 KB |
Output is correct |
10 |
Correct |
1 ms |
4952 KB |
Output is correct |
11 |
Correct |
1 ms |
4952 KB |
Output is correct |
12 |
Correct |
1 ms |
4952 KB |
Output is correct |
13 |
Correct |
1 ms |
4952 KB |
Output is correct |
14 |
Correct |
2 ms |
5040 KB |
Output is correct |
15 |
Correct |
2 ms |
5208 KB |
Output is correct |
16 |
Correct |
2 ms |
5208 KB |
Output is correct |
17 |
Correct |
2 ms |
5208 KB |
Output is correct |
18 |
Correct |
2 ms |
5460 KB |
Output is correct |
19 |
Correct |
2 ms |
5208 KB |
Output is correct |
20 |
Correct |
2 ms |
4952 KB |
Output is correct |
21 |
Correct |
2 ms |
4952 KB |
Output is correct |
22 |
Correct |
2 ms |
4948 KB |
Output is correct |
23 |
Correct |
2 ms |
4952 KB |
Output is correct |
24 |
Correct |
2 ms |
5032 KB |
Output is correct |
25 |
Correct |
2 ms |
5208 KB |
Output is correct |
26 |
Correct |
2 ms |
5208 KB |
Output is correct |
27 |
Correct |
2 ms |
5208 KB |
Output is correct |
28 |
Correct |
2 ms |
5208 KB |
Output is correct |
29 |
Correct |
1 ms |
4952 KB |
Output is correct |
30 |
Correct |
1 ms |
4952 KB |
Output is correct |
31 |
Correct |
1 ms |
5208 KB |
Output is correct |
32 |
Correct |
2 ms |
5208 KB |
Output is correct |
33 |
Correct |
2 ms |
4952 KB |
Output is correct |
34 |
Correct |
2 ms |
4952 KB |
Output is correct |
35 |
Correct |
1 ms |
4952 KB |
Output is correct |
36 |
Correct |
2 ms |
5208 KB |
Output is correct |
37 |
Correct |
2 ms |
5208 KB |
Output is correct |
38 |
Correct |
2 ms |
5208 KB |
Output is correct |
39 |
Correct |
2 ms |
4952 KB |
Output is correct |
40 |
Correct |
2 ms |
4952 KB |
Output is correct |
41 |
Correct |
2 ms |
4952 KB |
Output is correct |
42 |
Correct |
2 ms |
4952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3100 ms |
7256 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3100 ms |
7256 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
1 ms |
4952 KB |
Output is correct |
3 |
Correct |
1 ms |
4952 KB |
Output is correct |
4 |
Correct |
1 ms |
4952 KB |
Output is correct |
5 |
Correct |
1 ms |
4952 KB |
Output is correct |
6 |
Correct |
2 ms |
5040 KB |
Output is correct |
7 |
Correct |
2 ms |
5208 KB |
Output is correct |
8 |
Correct |
2 ms |
5208 KB |
Output is correct |
9 |
Correct |
2 ms |
5208 KB |
Output is correct |
10 |
Correct |
2 ms |
5460 KB |
Output is correct |
11 |
Correct |
2 ms |
5208 KB |
Output is correct |
12 |
Correct |
2 ms |
4952 KB |
Output is correct |
13 |
Execution timed out |
3100 ms |
7256 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4952 KB |
Output is correct |
2 |
Correct |
1 ms |
4952 KB |
Output is correct |
3 |
Correct |
2 ms |
5096 KB |
Output is correct |
4 |
Correct |
2 ms |
4952 KB |
Output is correct |
5 |
Correct |
2 ms |
4952 KB |
Output is correct |
6 |
Correct |
2 ms |
4952 KB |
Output is correct |
7 |
Correct |
2 ms |
4952 KB |
Output is correct |
8 |
Correct |
2 ms |
4952 KB |
Output is correct |
9 |
Correct |
2 ms |
4952 KB |
Output is correct |
10 |
Correct |
1 ms |
4952 KB |
Output is correct |
11 |
Correct |
1 ms |
4952 KB |
Output is correct |
12 |
Correct |
1 ms |
4952 KB |
Output is correct |
13 |
Correct |
1 ms |
4952 KB |
Output is correct |
14 |
Correct |
2 ms |
5040 KB |
Output is correct |
15 |
Correct |
2 ms |
5208 KB |
Output is correct |
16 |
Correct |
2 ms |
5208 KB |
Output is correct |
17 |
Correct |
2 ms |
5208 KB |
Output is correct |
18 |
Correct |
2 ms |
5460 KB |
Output is correct |
19 |
Correct |
2 ms |
5208 KB |
Output is correct |
20 |
Correct |
2 ms |
4952 KB |
Output is correct |
21 |
Correct |
2 ms |
4952 KB |
Output is correct |
22 |
Correct |
2 ms |
4948 KB |
Output is correct |
23 |
Correct |
2 ms |
4952 KB |
Output is correct |
24 |
Correct |
2 ms |
5032 KB |
Output is correct |
25 |
Correct |
2 ms |
5208 KB |
Output is correct |
26 |
Correct |
2 ms |
5208 KB |
Output is correct |
27 |
Correct |
2 ms |
5208 KB |
Output is correct |
28 |
Correct |
2 ms |
5208 KB |
Output is correct |
29 |
Correct |
1 ms |
4952 KB |
Output is correct |
30 |
Correct |
1 ms |
4952 KB |
Output is correct |
31 |
Correct |
1 ms |
5208 KB |
Output is correct |
32 |
Correct |
2 ms |
5208 KB |
Output is correct |
33 |
Correct |
2 ms |
4952 KB |
Output is correct |
34 |
Correct |
2 ms |
4952 KB |
Output is correct |
35 |
Correct |
1 ms |
4952 KB |
Output is correct |
36 |
Correct |
2 ms |
5208 KB |
Output is correct |
37 |
Correct |
2 ms |
5208 KB |
Output is correct |
38 |
Correct |
2 ms |
5208 KB |
Output is correct |
39 |
Correct |
2 ms |
4952 KB |
Output is correct |
40 |
Correct |
2 ms |
4952 KB |
Output is correct |
41 |
Correct |
2 ms |
4952 KB |
Output is correct |
42 |
Correct |
2 ms |
4952 KB |
Output is correct |
43 |
Execution timed out |
3088 ms |
5208 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4952 KB |
Output is correct |
2 |
Correct |
1 ms |
4952 KB |
Output is correct |
3 |
Correct |
2 ms |
5096 KB |
Output is correct |
4 |
Correct |
2 ms |
4952 KB |
Output is correct |
5 |
Correct |
2 ms |
4952 KB |
Output is correct |
6 |
Correct |
2 ms |
4952 KB |
Output is correct |
7 |
Correct |
2 ms |
4952 KB |
Output is correct |
8 |
Correct |
2 ms |
4952 KB |
Output is correct |
9 |
Correct |
2 ms |
4952 KB |
Output is correct |
10 |
Correct |
1 ms |
4952 KB |
Output is correct |
11 |
Correct |
1 ms |
4952 KB |
Output is correct |
12 |
Correct |
1 ms |
4952 KB |
Output is correct |
13 |
Correct |
1 ms |
4952 KB |
Output is correct |
14 |
Correct |
2 ms |
5040 KB |
Output is correct |
15 |
Correct |
2 ms |
5208 KB |
Output is correct |
16 |
Correct |
2 ms |
5208 KB |
Output is correct |
17 |
Correct |
2 ms |
5208 KB |
Output is correct |
18 |
Correct |
2 ms |
5460 KB |
Output is correct |
19 |
Correct |
2 ms |
5208 KB |
Output is correct |
20 |
Correct |
2 ms |
4952 KB |
Output is correct |
21 |
Correct |
2 ms |
4952 KB |
Output is correct |
22 |
Correct |
2 ms |
4948 KB |
Output is correct |
23 |
Correct |
2 ms |
4952 KB |
Output is correct |
24 |
Correct |
2 ms |
5032 KB |
Output is correct |
25 |
Correct |
2 ms |
5208 KB |
Output is correct |
26 |
Correct |
2 ms |
5208 KB |
Output is correct |
27 |
Correct |
2 ms |
5208 KB |
Output is correct |
28 |
Correct |
2 ms |
5208 KB |
Output is correct |
29 |
Correct |
1 ms |
4952 KB |
Output is correct |
30 |
Correct |
1 ms |
4952 KB |
Output is correct |
31 |
Correct |
1 ms |
5208 KB |
Output is correct |
32 |
Correct |
2 ms |
5208 KB |
Output is correct |
33 |
Correct |
2 ms |
4952 KB |
Output is correct |
34 |
Correct |
2 ms |
4952 KB |
Output is correct |
35 |
Correct |
1 ms |
4952 KB |
Output is correct |
36 |
Correct |
2 ms |
5208 KB |
Output is correct |
37 |
Correct |
2 ms |
5208 KB |
Output is correct |
38 |
Correct |
2 ms |
5208 KB |
Output is correct |
39 |
Correct |
2 ms |
4952 KB |
Output is correct |
40 |
Correct |
2 ms |
4952 KB |
Output is correct |
41 |
Correct |
2 ms |
4952 KB |
Output is correct |
42 |
Correct |
2 ms |
4952 KB |
Output is correct |
43 |
Execution timed out |
3100 ms |
7256 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |