#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000002022;
const int maxn = 2e5 + 10;
int n, m, p[maxn], a[maxn];
vector < int > children[maxn];
ll dp[maxn][2], temp[maxn];
void update_state(int v)
{
int c = children[v].size();
for (int i = 0; i <= c; i ++)
temp[i] = 0;
temp[0] = 1;
for (int u : children[v])
{
for (int i = c; i >= 0; i --)
{
temp[i] = (temp[i] * dp[u][0]) % mod;
if (i > 0)
temp[i] = (temp[i] + temp[i - 1] * dp[u][1]) % mod;
}
}
for (int i = 0; i <= c; i ++)
{
dp[v][0] = (dp[v][0] + temp[i] * (ll)(c - i)) % mod;
dp[v][1] = (dp[v][1] + temp[i] * (ll)(i)) % mod;
}
}
void solve_state(int v)
{
dp[v][0] = dp[v][1] = 0;
if (v >= n)
{
dp[v][1] = a[v - n];
dp[v][0] = 1 - dp[v][1];
return;
}
for (int u : children[v])
{
solve_state(u);
}
update_state(v);
///cout << v << " " << dp[v][0] << " " << dp[v][1] << endl;
}
void init(int N, int M, std::vector<int> P, std::vector<int> A)
{
n = N;
m = M;
for (int i = 0; i < N + M; i ++)
p[i] = P[i];
for (int i = 0; i < M; i ++)
a[i] = A[i];
for (int i = 1; i < N + M; i ++)
{
children[p[i]].push_back(i);
}
}
int count_ways(int L, int R)
{
if (L == R)
{
a[L - n] = ((a[L - n] + 1) & 1);
int v = L;
while(v != -1)
{
update_state(v);
v = p[v];
}
}
else
{
for (int i = L - n; i <= R - n; i ++)
a[i] = ((a[i] + 1) & 1);
solve_state(0);
}
return dp[0][1];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4944 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
4944 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4944 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
686 ms |
7856 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
686 ms |
7856 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
4944 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4944 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4944 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |