#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)
{
dp[v][0] = dp[v][1] = 0;
if (v >= n)
{
dp[v][1] = a[v - n];
dp[v][0] = 1 - dp[v][1];
return;
}
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;
}
///cout << v << " " << dp[v][0] << " " << dp[v][1] << endl;
}
void solve_state(int v)
{
for (int u : children[v])
{
solve_state(u);
}
update_state(v);
}
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);
}
solve_state(0);
}
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];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Correct |
21 ms |
5072 KB |
Output is correct |
4 |
Correct |
20 ms |
5072 KB |
Output is correct |
5 |
Correct |
23 ms |
5068 KB |
Output is correct |
6 |
Correct |
22 ms |
4944 KB |
Output is correct |
7 |
Correct |
26 ms |
5024 KB |
Output is correct |
8 |
Correct |
21 ms |
5068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4944 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 |
5072 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 |
5012 KB |
Output is correct |
10 |
Correct |
3 ms |
5072 KB |
Output is correct |
11 |
Correct |
3 ms |
5072 KB |
Output is correct |
12 |
Correct |
4 ms |
5072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Correct |
21 ms |
5072 KB |
Output is correct |
4 |
Correct |
20 ms |
5072 KB |
Output is correct |
5 |
Correct |
23 ms |
5068 KB |
Output is correct |
6 |
Correct |
22 ms |
4944 KB |
Output is correct |
7 |
Correct |
26 ms |
5024 KB |
Output is correct |
8 |
Correct |
21 ms |
5068 KB |
Output is correct |
9 |
Correct |
3 ms |
4944 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 |
5072 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 |
5012 KB |
Output is correct |
18 |
Correct |
3 ms |
5072 KB |
Output is correct |
19 |
Correct |
3 ms |
5072 KB |
Output is correct |
20 |
Correct |
4 ms |
5072 KB |
Output is correct |
21 |
Correct |
5 ms |
5072 KB |
Output is correct |
22 |
Correct |
3 ms |
5072 KB |
Output is correct |
23 |
Correct |
3 ms |
5072 KB |
Output is correct |
24 |
Correct |
3 ms |
5072 KB |
Output is correct |
25 |
Correct |
4 ms |
5072 KB |
Output is correct |
26 |
Correct |
4 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 |
20 ms |
5072 KB |
Output is correct |
30 |
Correct |
27 ms |
5072 KB |
Output is correct |
31 |
Correct |
3 ms |
5072 KB |
Output is correct |
32 |
Correct |
4 ms |
5072 KB |
Output is correct |
33 |
Correct |
4 ms |
5072 KB |
Output is correct |
34 |
Correct |
4 ms |
5072 KB |
Output is correct |
35 |
Correct |
7 ms |
4944 KB |
Output is correct |
36 |
Correct |
3 ms |
5072 KB |
Output is correct |
37 |
Correct |
20 ms |
5152 KB |
Output is correct |
38 |
Correct |
22 ms |
5148 KB |
Output is correct |
39 |
Correct |
3 ms |
5072 KB |
Output is correct |
40 |
Correct |
3 ms |
5072 KB |
Output is correct |
41 |
Correct |
3 ms |
5020 KB |
Output is correct |
42 |
Correct |
4 ms |
4944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
743 ms |
8196 KB |
Output is correct |
2 |
Correct |
922 ms |
11388 KB |
Output is correct |
3 |
Correct |
1029 ms |
11396 KB |
Output is correct |
4 |
Correct |
985 ms |
11336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
743 ms |
8196 KB |
Output is correct |
2 |
Correct |
922 ms |
11388 KB |
Output is correct |
3 |
Correct |
1029 ms |
11396 KB |
Output is correct |
4 |
Correct |
985 ms |
11336 KB |
Output is correct |
5 |
Execution timed out |
3044 ms |
8184 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4944 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 |
5072 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 |
5012 KB |
Output is correct |
10 |
Correct |
3 ms |
5072 KB |
Output is correct |
11 |
Correct |
3 ms |
5072 KB |
Output is correct |
12 |
Correct |
4 ms |
5072 KB |
Output is correct |
13 |
Correct |
743 ms |
8196 KB |
Output is correct |
14 |
Correct |
922 ms |
11388 KB |
Output is correct |
15 |
Correct |
1029 ms |
11396 KB |
Output is correct |
16 |
Correct |
985 ms |
11336 KB |
Output is correct |
17 |
Execution timed out |
3044 ms |
8184 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Correct |
21 ms |
5072 KB |
Output is correct |
4 |
Correct |
20 ms |
5072 KB |
Output is correct |
5 |
Correct |
23 ms |
5068 KB |
Output is correct |
6 |
Correct |
22 ms |
4944 KB |
Output is correct |
7 |
Correct |
26 ms |
5024 KB |
Output is correct |
8 |
Correct |
21 ms |
5068 KB |
Output is correct |
9 |
Correct |
3 ms |
4944 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 |
5072 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 |
5012 KB |
Output is correct |
18 |
Correct |
3 ms |
5072 KB |
Output is correct |
19 |
Correct |
3 ms |
5072 KB |
Output is correct |
20 |
Correct |
4 ms |
5072 KB |
Output is correct |
21 |
Correct |
5 ms |
5072 KB |
Output is correct |
22 |
Correct |
3 ms |
5072 KB |
Output is correct |
23 |
Correct |
3 ms |
5072 KB |
Output is correct |
24 |
Correct |
3 ms |
5072 KB |
Output is correct |
25 |
Correct |
4 ms |
5072 KB |
Output is correct |
26 |
Correct |
4 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 |
20 ms |
5072 KB |
Output is correct |
30 |
Correct |
27 ms |
5072 KB |
Output is correct |
31 |
Correct |
3 ms |
5072 KB |
Output is correct |
32 |
Correct |
4 ms |
5072 KB |
Output is correct |
33 |
Correct |
4 ms |
5072 KB |
Output is correct |
34 |
Correct |
4 ms |
5072 KB |
Output is correct |
35 |
Correct |
7 ms |
4944 KB |
Output is correct |
36 |
Correct |
3 ms |
5072 KB |
Output is correct |
37 |
Correct |
20 ms |
5152 KB |
Output is correct |
38 |
Correct |
22 ms |
5148 KB |
Output is correct |
39 |
Correct |
3 ms |
5072 KB |
Output is correct |
40 |
Correct |
3 ms |
5072 KB |
Output is correct |
41 |
Correct |
3 ms |
5020 KB |
Output is correct |
42 |
Correct |
4 ms |
4944 KB |
Output is correct |
43 |
Execution timed out |
3078 ms |
5200 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Correct |
21 ms |
5072 KB |
Output is correct |
4 |
Correct |
20 ms |
5072 KB |
Output is correct |
5 |
Correct |
23 ms |
5068 KB |
Output is correct |
6 |
Correct |
22 ms |
4944 KB |
Output is correct |
7 |
Correct |
26 ms |
5024 KB |
Output is correct |
8 |
Correct |
21 ms |
5068 KB |
Output is correct |
9 |
Correct |
3 ms |
4944 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 |
5072 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 |
5012 KB |
Output is correct |
18 |
Correct |
3 ms |
5072 KB |
Output is correct |
19 |
Correct |
3 ms |
5072 KB |
Output is correct |
20 |
Correct |
4 ms |
5072 KB |
Output is correct |
21 |
Correct |
5 ms |
5072 KB |
Output is correct |
22 |
Correct |
3 ms |
5072 KB |
Output is correct |
23 |
Correct |
3 ms |
5072 KB |
Output is correct |
24 |
Correct |
3 ms |
5072 KB |
Output is correct |
25 |
Correct |
4 ms |
5072 KB |
Output is correct |
26 |
Correct |
4 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 |
20 ms |
5072 KB |
Output is correct |
30 |
Correct |
27 ms |
5072 KB |
Output is correct |
31 |
Correct |
3 ms |
5072 KB |
Output is correct |
32 |
Correct |
4 ms |
5072 KB |
Output is correct |
33 |
Correct |
4 ms |
5072 KB |
Output is correct |
34 |
Correct |
4 ms |
5072 KB |
Output is correct |
35 |
Correct |
7 ms |
4944 KB |
Output is correct |
36 |
Correct |
3 ms |
5072 KB |
Output is correct |
37 |
Correct |
20 ms |
5152 KB |
Output is correct |
38 |
Correct |
22 ms |
5148 KB |
Output is correct |
39 |
Correct |
3 ms |
5072 KB |
Output is correct |
40 |
Correct |
3 ms |
5072 KB |
Output is correct |
41 |
Correct |
3 ms |
5020 KB |
Output is correct |
42 |
Correct |
4 ms |
4944 KB |
Output is correct |
43 |
Correct |
743 ms |
8196 KB |
Output is correct |
44 |
Correct |
922 ms |
11388 KB |
Output is correct |
45 |
Correct |
1029 ms |
11396 KB |
Output is correct |
46 |
Correct |
985 ms |
11336 KB |
Output is correct |
47 |
Execution timed out |
3044 ms |
8184 KB |
Time limit exceeded |
48 |
Halted |
0 ms |
0 KB |
- |