#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() );
//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 |
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 |
1 ms |
4952 KB |
Output is correct |
7 |
Correct |
1 ms |
4952 KB |
Output is correct |
8 |
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 |
4952 KB |
Output is correct |
4 |
Correct |
2 ms |
4952 KB |
Output is correct |
5 |
Correct |
1 ms |
4952 KB |
Output is correct |
6 |
Incorrect |
2 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '706880838', found: '-171188108' |
7 |
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 |
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 |
1 ms |
4952 KB |
Output is correct |
7 |
Correct |
1 ms |
4952 KB |
Output is correct |
8 |
Correct |
2 ms |
4952 KB |
Output is correct |
9 |
Correct |
1 ms |
4952 KB |
Output is correct |
10 |
Correct |
1 ms |
4952 KB |
Output is correct |
11 |
Correct |
2 ms |
4952 KB |
Output is correct |
12 |
Correct |
2 ms |
4952 KB |
Output is correct |
13 |
Correct |
1 ms |
4952 KB |
Output is correct |
14 |
Incorrect |
2 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '706880838', found: '-171188108' |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3067 ms |
7076 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3067 ms |
7076 KB |
Time limit exceeded |
2 |
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 |
4952 KB |
Output is correct |
4 |
Correct |
2 ms |
4952 KB |
Output is correct |
5 |
Correct |
1 ms |
4952 KB |
Output is correct |
6 |
Incorrect |
2 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '706880838', found: '-171188108' |
7 |
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 |
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 |
1 ms |
4952 KB |
Output is correct |
7 |
Correct |
1 ms |
4952 KB |
Output is correct |
8 |
Correct |
2 ms |
4952 KB |
Output is correct |
9 |
Correct |
1 ms |
4952 KB |
Output is correct |
10 |
Correct |
1 ms |
4952 KB |
Output is correct |
11 |
Correct |
2 ms |
4952 KB |
Output is correct |
12 |
Correct |
2 ms |
4952 KB |
Output is correct |
13 |
Correct |
1 ms |
4952 KB |
Output is correct |
14 |
Incorrect |
2 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '706880838', found: '-171188108' |
15 |
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 |
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 |
1 ms |
4952 KB |
Output is correct |
7 |
Correct |
1 ms |
4952 KB |
Output is correct |
8 |
Correct |
2 ms |
4952 KB |
Output is correct |
9 |
Correct |
1 ms |
4952 KB |
Output is correct |
10 |
Correct |
1 ms |
4952 KB |
Output is correct |
11 |
Correct |
2 ms |
4952 KB |
Output is correct |
12 |
Correct |
2 ms |
4952 KB |
Output is correct |
13 |
Correct |
1 ms |
4952 KB |
Output is correct |
14 |
Incorrect |
2 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '706880838', found: '-171188108' |
15 |
Halted |
0 ms |
0 KB |
- |