// O(N^2)
#include <bits/stdc++.h>
#include "circuit.h"
using namespace std;
const int BASE = 1e9 + 2022;
const int N = 100100;
int n, m;
vector<int> a[N];
vector<int> states;
vector<vector<long long>> f;
void init(int N, int M, vector<int> P, vector<int> A)
{
n = N;
m = M;
for (int i = 1; i < n + m; i++)
a[P[i]].push_back(i);
states = A;
f = vector<vector<long long>>(n + m, vector<long long>(2));
}
void calc(int x)
{
if (x >= n)
{
f[x] = {states[x - n] ^ 1, states[x - n]};
return;
}
vector<long long> ways(size(a[x]) + 1);
ways[0] = 1;
int curSz = 0;
for (int y : a[x])
{
calc(y);
for (int i = curSz; i >= 0; i--)
{
ways[i + 1] += ways[i] * f[y][1];
ways[i + 1] %= BASE;
ways[i] *= f[y][0];
ways[i] %= BASE;
}
curSz++;
}
f[x][0] = f[x][1] = 0;
for (int i = 1; i <= curSz; i++)
ways[i] = (ways[i] + ways[i - 1]) % BASE;
for (int i = 1; i <= curSz; i++)
{
f[x][1] += ways[curSz] - ways[i - 1] + BASE;
f[x][1] %= BASE;
f[x][0] += ways[i - 1];
f[x][0] %= BASE;
}
}
int count_ways(int L, int R)
{
for (int i = L; i <= R; i++)
states[i - n] ^= 1;
calc(0);
return int(f[0][1]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
3 ms |
2640 KB |
Output is correct |
3 |
Correct |
10 ms |
2640 KB |
Output is correct |
4 |
Correct |
10 ms |
2640 KB |
Output is correct |
5 |
Correct |
10 ms |
2640 KB |
Output is correct |
6 |
Correct |
10 ms |
2640 KB |
Output is correct |
7 |
Correct |
10 ms |
2728 KB |
Output is correct |
8 |
Correct |
10 ms |
2640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2640 KB |
Output is correct |
4 |
Correct |
2 ms |
2640 KB |
Output is correct |
5 |
Correct |
2 ms |
2640 KB |
Output is correct |
6 |
Correct |
2 ms |
2768 KB |
Output is correct |
7 |
Correct |
2 ms |
2768 KB |
Output is correct |
8 |
Correct |
2 ms |
2768 KB |
Output is correct |
9 |
Correct |
2 ms |
2768 KB |
Output is correct |
10 |
Correct |
4 ms |
2984 KB |
Output is correct |
11 |
Correct |
2 ms |
2896 KB |
Output is correct |
12 |
Correct |
2 ms |
2768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
3 ms |
2640 KB |
Output is correct |
3 |
Correct |
10 ms |
2640 KB |
Output is correct |
4 |
Correct |
10 ms |
2640 KB |
Output is correct |
5 |
Correct |
10 ms |
2640 KB |
Output is correct |
6 |
Correct |
10 ms |
2640 KB |
Output is correct |
7 |
Correct |
10 ms |
2728 KB |
Output is correct |
8 |
Correct |
10 ms |
2640 KB |
Output is correct |
9 |
Correct |
1 ms |
2640 KB |
Output is correct |
10 |
Correct |
1 ms |
2640 KB |
Output is correct |
11 |
Correct |
2 ms |
2640 KB |
Output is correct |
12 |
Correct |
2 ms |
2640 KB |
Output is correct |
13 |
Correct |
2 ms |
2640 KB |
Output is correct |
14 |
Correct |
2 ms |
2768 KB |
Output is correct |
15 |
Correct |
2 ms |
2768 KB |
Output is correct |
16 |
Correct |
2 ms |
2768 KB |
Output is correct |
17 |
Correct |
2 ms |
2768 KB |
Output is correct |
18 |
Correct |
4 ms |
2984 KB |
Output is correct |
19 |
Correct |
2 ms |
2896 KB |
Output is correct |
20 |
Correct |
2 ms |
2768 KB |
Output is correct |
21 |
Correct |
2 ms |
2768 KB |
Output is correct |
22 |
Correct |
2 ms |
2640 KB |
Output is correct |
23 |
Correct |
2 ms |
2640 KB |
Output is correct |
24 |
Correct |
2 ms |
2768 KB |
Output is correct |
25 |
Correct |
2 ms |
2768 KB |
Output is correct |
26 |
Correct |
3 ms |
2768 KB |
Output is correct |
27 |
Correct |
3 ms |
2768 KB |
Output is correct |
28 |
Correct |
4 ms |
2768 KB |
Output is correct |
29 |
Correct |
13 ms |
2640 KB |
Output is correct |
30 |
Correct |
10 ms |
2732 KB |
Output is correct |
31 |
Correct |
2 ms |
2896 KB |
Output is correct |
32 |
Correct |
2 ms |
2768 KB |
Output is correct |
33 |
Correct |
2 ms |
2640 KB |
Output is correct |
34 |
Correct |
2 ms |
2668 KB |
Output is correct |
35 |
Correct |
3 ms |
2724 KB |
Output is correct |
36 |
Correct |
3 ms |
2896 KB |
Output is correct |
37 |
Correct |
10 ms |
2984 KB |
Output is correct |
38 |
Correct |
11 ms |
2896 KB |
Output is correct |
39 |
Correct |
2 ms |
2768 KB |
Output is correct |
40 |
Correct |
2 ms |
2640 KB |
Output is correct |
41 |
Correct |
2 ms |
2652 KB |
Output is correct |
42 |
Correct |
2 ms |
2640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3053 ms |
8144 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3053 ms |
8144 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2640 KB |
Output is correct |
4 |
Correct |
2 ms |
2640 KB |
Output is correct |
5 |
Correct |
2 ms |
2640 KB |
Output is correct |
6 |
Correct |
2 ms |
2768 KB |
Output is correct |
7 |
Correct |
2 ms |
2768 KB |
Output is correct |
8 |
Correct |
2 ms |
2768 KB |
Output is correct |
9 |
Correct |
2 ms |
2768 KB |
Output is correct |
10 |
Correct |
4 ms |
2984 KB |
Output is correct |
11 |
Correct |
2 ms |
2896 KB |
Output is correct |
12 |
Correct |
2 ms |
2768 KB |
Output is correct |
13 |
Execution timed out |
3053 ms |
8144 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
3 ms |
2640 KB |
Output is correct |
3 |
Correct |
10 ms |
2640 KB |
Output is correct |
4 |
Correct |
10 ms |
2640 KB |
Output is correct |
5 |
Correct |
10 ms |
2640 KB |
Output is correct |
6 |
Correct |
10 ms |
2640 KB |
Output is correct |
7 |
Correct |
10 ms |
2728 KB |
Output is correct |
8 |
Correct |
10 ms |
2640 KB |
Output is correct |
9 |
Correct |
1 ms |
2640 KB |
Output is correct |
10 |
Correct |
1 ms |
2640 KB |
Output is correct |
11 |
Correct |
2 ms |
2640 KB |
Output is correct |
12 |
Correct |
2 ms |
2640 KB |
Output is correct |
13 |
Correct |
2 ms |
2640 KB |
Output is correct |
14 |
Correct |
2 ms |
2768 KB |
Output is correct |
15 |
Correct |
2 ms |
2768 KB |
Output is correct |
16 |
Correct |
2 ms |
2768 KB |
Output is correct |
17 |
Correct |
2 ms |
2768 KB |
Output is correct |
18 |
Correct |
4 ms |
2984 KB |
Output is correct |
19 |
Correct |
2 ms |
2896 KB |
Output is correct |
20 |
Correct |
2 ms |
2768 KB |
Output is correct |
21 |
Correct |
2 ms |
2768 KB |
Output is correct |
22 |
Correct |
2 ms |
2640 KB |
Output is correct |
23 |
Correct |
2 ms |
2640 KB |
Output is correct |
24 |
Correct |
2 ms |
2768 KB |
Output is correct |
25 |
Correct |
2 ms |
2768 KB |
Output is correct |
26 |
Correct |
3 ms |
2768 KB |
Output is correct |
27 |
Correct |
3 ms |
2768 KB |
Output is correct |
28 |
Correct |
4 ms |
2768 KB |
Output is correct |
29 |
Correct |
13 ms |
2640 KB |
Output is correct |
30 |
Correct |
10 ms |
2732 KB |
Output is correct |
31 |
Correct |
2 ms |
2896 KB |
Output is correct |
32 |
Correct |
2 ms |
2768 KB |
Output is correct |
33 |
Correct |
2 ms |
2640 KB |
Output is correct |
34 |
Correct |
2 ms |
2668 KB |
Output is correct |
35 |
Correct |
3 ms |
2724 KB |
Output is correct |
36 |
Correct |
3 ms |
2896 KB |
Output is correct |
37 |
Correct |
10 ms |
2984 KB |
Output is correct |
38 |
Correct |
11 ms |
2896 KB |
Output is correct |
39 |
Correct |
2 ms |
2768 KB |
Output is correct |
40 |
Correct |
2 ms |
2640 KB |
Output is correct |
41 |
Correct |
2 ms |
2652 KB |
Output is correct |
42 |
Correct |
2 ms |
2640 KB |
Output is correct |
43 |
Execution timed out |
3051 ms |
3152 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
3 ms |
2640 KB |
Output is correct |
3 |
Correct |
10 ms |
2640 KB |
Output is correct |
4 |
Correct |
10 ms |
2640 KB |
Output is correct |
5 |
Correct |
10 ms |
2640 KB |
Output is correct |
6 |
Correct |
10 ms |
2640 KB |
Output is correct |
7 |
Correct |
10 ms |
2728 KB |
Output is correct |
8 |
Correct |
10 ms |
2640 KB |
Output is correct |
9 |
Correct |
1 ms |
2640 KB |
Output is correct |
10 |
Correct |
1 ms |
2640 KB |
Output is correct |
11 |
Correct |
2 ms |
2640 KB |
Output is correct |
12 |
Correct |
2 ms |
2640 KB |
Output is correct |
13 |
Correct |
2 ms |
2640 KB |
Output is correct |
14 |
Correct |
2 ms |
2768 KB |
Output is correct |
15 |
Correct |
2 ms |
2768 KB |
Output is correct |
16 |
Correct |
2 ms |
2768 KB |
Output is correct |
17 |
Correct |
2 ms |
2768 KB |
Output is correct |
18 |
Correct |
4 ms |
2984 KB |
Output is correct |
19 |
Correct |
2 ms |
2896 KB |
Output is correct |
20 |
Correct |
2 ms |
2768 KB |
Output is correct |
21 |
Correct |
2 ms |
2768 KB |
Output is correct |
22 |
Correct |
2 ms |
2640 KB |
Output is correct |
23 |
Correct |
2 ms |
2640 KB |
Output is correct |
24 |
Correct |
2 ms |
2768 KB |
Output is correct |
25 |
Correct |
2 ms |
2768 KB |
Output is correct |
26 |
Correct |
3 ms |
2768 KB |
Output is correct |
27 |
Correct |
3 ms |
2768 KB |
Output is correct |
28 |
Correct |
4 ms |
2768 KB |
Output is correct |
29 |
Correct |
13 ms |
2640 KB |
Output is correct |
30 |
Correct |
10 ms |
2732 KB |
Output is correct |
31 |
Correct |
2 ms |
2896 KB |
Output is correct |
32 |
Correct |
2 ms |
2768 KB |
Output is correct |
33 |
Correct |
2 ms |
2640 KB |
Output is correct |
34 |
Correct |
2 ms |
2668 KB |
Output is correct |
35 |
Correct |
3 ms |
2724 KB |
Output is correct |
36 |
Correct |
3 ms |
2896 KB |
Output is correct |
37 |
Correct |
10 ms |
2984 KB |
Output is correct |
38 |
Correct |
11 ms |
2896 KB |
Output is correct |
39 |
Correct |
2 ms |
2768 KB |
Output is correct |
40 |
Correct |
2 ms |
2640 KB |
Output is correct |
41 |
Correct |
2 ms |
2652 KB |
Output is correct |
42 |
Correct |
2 ms |
2640 KB |
Output is correct |
43 |
Execution timed out |
3053 ms |
8144 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |