#include "circuit.h"
//#include "stub.cpp"
#include <bits/stdc++.h>
using namespace std;
const long long MOD= 1000002022;
vector<int> a;
vector<int> adj[100005];
int n, m;
pair<long long, long long> dfs(int s) {
if (s>=n) {
return {a[s-n], a[s-n]^1};
}
vector<long long> dp(adj[s].size()+1, 0);
dp[0]=1;
for (auto u: adj[s]) {
auto act=dfs(u);
for (int i=dp.size()-1; i>=0; i--) {
dp[i]=(dp[i]*act.second)%MOD;
if (i>0) {
dp[i]+=(dp[i-1]*act.first)%MOD;
}
dp[i]%=MOD;
}
}
pair<long long, long long> ans={0, 0};
for (int i=1; i<(int)dp.size()-1; i++) {
ans.first+=(dp[i]*i)%MOD;
ans.second+=(dp[i]*(dp.size()-i-1));
ans.first%=MOD, ans.second%=MOD;
}
ans.first+=dp[dp.size()-1]*(dp.size()-1);
ans.second+=dp[0]*(dp.size()-1);
return {ans.first%MOD, ans.second%MOD};
}
void init(int N, int M, vector<int> p, vector<int> aa) {
a=aa;
n=N, m=M;
for (int i=1; i<n+m; i++) {
adj[p[i]].push_back(i);
}
}
int count_ways(int L, int R) {
for (int i=L; i<=R; i++) {
a[i-n]^=1;
}
return dfs(0).first;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Correct |
18 ms |
2808 KB |
Output is correct |
4 |
Correct |
17 ms |
2648 KB |
Output is correct |
5 |
Correct |
18 ms |
2648 KB |
Output is correct |
6 |
Correct |
18 ms |
2648 KB |
Output is correct |
7 |
Correct |
18 ms |
2644 KB |
Output is correct |
8 |
Correct |
17 ms |
2648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Correct |
1 ms |
2900 KB |
Output is correct |
4 |
Correct |
1 ms |
2648 KB |
Output is correct |
5 |
Correct |
1 ms |
2648 KB |
Output is correct |
6 |
Correct |
1 ms |
2648 KB |
Output is correct |
7 |
Correct |
2 ms |
2648 KB |
Output is correct |
8 |
Correct |
2 ms |
2648 KB |
Output is correct |
9 |
Correct |
1 ms |
2648 KB |
Output is correct |
10 |
Correct |
1 ms |
2904 KB |
Output is correct |
11 |
Correct |
1 ms |
2948 KB |
Output is correct |
12 |
Correct |
2 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Correct |
18 ms |
2808 KB |
Output is correct |
4 |
Correct |
17 ms |
2648 KB |
Output is correct |
5 |
Correct |
18 ms |
2648 KB |
Output is correct |
6 |
Correct |
18 ms |
2648 KB |
Output is correct |
7 |
Correct |
18 ms |
2644 KB |
Output is correct |
8 |
Correct |
17 ms |
2648 KB |
Output is correct |
9 |
Correct |
1 ms |
2648 KB |
Output is correct |
10 |
Correct |
1 ms |
2648 KB |
Output is correct |
11 |
Correct |
1 ms |
2900 KB |
Output is correct |
12 |
Correct |
1 ms |
2648 KB |
Output is correct |
13 |
Correct |
1 ms |
2648 KB |
Output is correct |
14 |
Correct |
1 ms |
2648 KB |
Output is correct |
15 |
Correct |
2 ms |
2648 KB |
Output is correct |
16 |
Correct |
2 ms |
2648 KB |
Output is correct |
17 |
Correct |
1 ms |
2648 KB |
Output is correct |
18 |
Correct |
1 ms |
2904 KB |
Output is correct |
19 |
Correct |
1 ms |
2948 KB |
Output is correct |
20 |
Correct |
2 ms |
2644 KB |
Output is correct |
21 |
Correct |
1 ms |
2648 KB |
Output is correct |
22 |
Correct |
1 ms |
2904 KB |
Output is correct |
23 |
Correct |
1 ms |
2648 KB |
Output is correct |
24 |
Correct |
1 ms |
2900 KB |
Output is correct |
25 |
Correct |
1 ms |
2644 KB |
Output is correct |
26 |
Correct |
1 ms |
2648 KB |
Output is correct |
27 |
Correct |
1 ms |
2648 KB |
Output is correct |
28 |
Correct |
1 ms |
2648 KB |
Output is correct |
29 |
Correct |
17 ms |
2808 KB |
Output is correct |
30 |
Correct |
17 ms |
2648 KB |
Output is correct |
31 |
Correct |
1 ms |
2904 KB |
Output is correct |
32 |
Correct |
1 ms |
2648 KB |
Output is correct |
33 |
Correct |
1 ms |
2648 KB |
Output is correct |
34 |
Correct |
1 ms |
2648 KB |
Output is correct |
35 |
Correct |
4 ms |
2648 KB |
Output is correct |
36 |
Correct |
1 ms |
2904 KB |
Output is correct |
37 |
Correct |
17 ms |
2960 KB |
Output is correct |
38 |
Correct |
17 ms |
2904 KB |
Output is correct |
39 |
Correct |
1 ms |
2648 KB |
Output is correct |
40 |
Correct |
1 ms |
2648 KB |
Output is correct |
41 |
Correct |
1 ms |
2648 KB |
Output is correct |
42 |
Correct |
1 ms |
2648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3089 ms |
4720 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3089 ms |
4720 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Correct |
1 ms |
2900 KB |
Output is correct |
4 |
Correct |
1 ms |
2648 KB |
Output is correct |
5 |
Correct |
1 ms |
2648 KB |
Output is correct |
6 |
Correct |
1 ms |
2648 KB |
Output is correct |
7 |
Correct |
2 ms |
2648 KB |
Output is correct |
8 |
Correct |
2 ms |
2648 KB |
Output is correct |
9 |
Correct |
1 ms |
2648 KB |
Output is correct |
10 |
Correct |
1 ms |
2904 KB |
Output is correct |
11 |
Correct |
1 ms |
2948 KB |
Output is correct |
12 |
Correct |
2 ms |
2644 KB |
Output is correct |
13 |
Execution timed out |
3089 ms |
4720 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Correct |
18 ms |
2808 KB |
Output is correct |
4 |
Correct |
17 ms |
2648 KB |
Output is correct |
5 |
Correct |
18 ms |
2648 KB |
Output is correct |
6 |
Correct |
18 ms |
2648 KB |
Output is correct |
7 |
Correct |
18 ms |
2644 KB |
Output is correct |
8 |
Correct |
17 ms |
2648 KB |
Output is correct |
9 |
Correct |
1 ms |
2648 KB |
Output is correct |
10 |
Correct |
1 ms |
2648 KB |
Output is correct |
11 |
Correct |
1 ms |
2900 KB |
Output is correct |
12 |
Correct |
1 ms |
2648 KB |
Output is correct |
13 |
Correct |
1 ms |
2648 KB |
Output is correct |
14 |
Correct |
1 ms |
2648 KB |
Output is correct |
15 |
Correct |
2 ms |
2648 KB |
Output is correct |
16 |
Correct |
2 ms |
2648 KB |
Output is correct |
17 |
Correct |
1 ms |
2648 KB |
Output is correct |
18 |
Correct |
1 ms |
2904 KB |
Output is correct |
19 |
Correct |
1 ms |
2948 KB |
Output is correct |
20 |
Correct |
2 ms |
2644 KB |
Output is correct |
21 |
Correct |
1 ms |
2648 KB |
Output is correct |
22 |
Correct |
1 ms |
2904 KB |
Output is correct |
23 |
Correct |
1 ms |
2648 KB |
Output is correct |
24 |
Correct |
1 ms |
2900 KB |
Output is correct |
25 |
Correct |
1 ms |
2644 KB |
Output is correct |
26 |
Correct |
1 ms |
2648 KB |
Output is correct |
27 |
Correct |
1 ms |
2648 KB |
Output is correct |
28 |
Correct |
1 ms |
2648 KB |
Output is correct |
29 |
Correct |
17 ms |
2808 KB |
Output is correct |
30 |
Correct |
17 ms |
2648 KB |
Output is correct |
31 |
Correct |
1 ms |
2904 KB |
Output is correct |
32 |
Correct |
1 ms |
2648 KB |
Output is correct |
33 |
Correct |
1 ms |
2648 KB |
Output is correct |
34 |
Correct |
1 ms |
2648 KB |
Output is correct |
35 |
Correct |
4 ms |
2648 KB |
Output is correct |
36 |
Correct |
1 ms |
2904 KB |
Output is correct |
37 |
Correct |
17 ms |
2960 KB |
Output is correct |
38 |
Correct |
17 ms |
2904 KB |
Output is correct |
39 |
Correct |
1 ms |
2648 KB |
Output is correct |
40 |
Correct |
1 ms |
2648 KB |
Output is correct |
41 |
Correct |
1 ms |
2648 KB |
Output is correct |
42 |
Correct |
1 ms |
2648 KB |
Output is correct |
43 |
Execution timed out |
3071 ms |
2904 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Correct |
18 ms |
2808 KB |
Output is correct |
4 |
Correct |
17 ms |
2648 KB |
Output is correct |
5 |
Correct |
18 ms |
2648 KB |
Output is correct |
6 |
Correct |
18 ms |
2648 KB |
Output is correct |
7 |
Correct |
18 ms |
2644 KB |
Output is correct |
8 |
Correct |
17 ms |
2648 KB |
Output is correct |
9 |
Correct |
1 ms |
2648 KB |
Output is correct |
10 |
Correct |
1 ms |
2648 KB |
Output is correct |
11 |
Correct |
1 ms |
2900 KB |
Output is correct |
12 |
Correct |
1 ms |
2648 KB |
Output is correct |
13 |
Correct |
1 ms |
2648 KB |
Output is correct |
14 |
Correct |
1 ms |
2648 KB |
Output is correct |
15 |
Correct |
2 ms |
2648 KB |
Output is correct |
16 |
Correct |
2 ms |
2648 KB |
Output is correct |
17 |
Correct |
1 ms |
2648 KB |
Output is correct |
18 |
Correct |
1 ms |
2904 KB |
Output is correct |
19 |
Correct |
1 ms |
2948 KB |
Output is correct |
20 |
Correct |
2 ms |
2644 KB |
Output is correct |
21 |
Correct |
1 ms |
2648 KB |
Output is correct |
22 |
Correct |
1 ms |
2904 KB |
Output is correct |
23 |
Correct |
1 ms |
2648 KB |
Output is correct |
24 |
Correct |
1 ms |
2900 KB |
Output is correct |
25 |
Correct |
1 ms |
2644 KB |
Output is correct |
26 |
Correct |
1 ms |
2648 KB |
Output is correct |
27 |
Correct |
1 ms |
2648 KB |
Output is correct |
28 |
Correct |
1 ms |
2648 KB |
Output is correct |
29 |
Correct |
17 ms |
2808 KB |
Output is correct |
30 |
Correct |
17 ms |
2648 KB |
Output is correct |
31 |
Correct |
1 ms |
2904 KB |
Output is correct |
32 |
Correct |
1 ms |
2648 KB |
Output is correct |
33 |
Correct |
1 ms |
2648 KB |
Output is correct |
34 |
Correct |
1 ms |
2648 KB |
Output is correct |
35 |
Correct |
4 ms |
2648 KB |
Output is correct |
36 |
Correct |
1 ms |
2904 KB |
Output is correct |
37 |
Correct |
17 ms |
2960 KB |
Output is correct |
38 |
Correct |
17 ms |
2904 KB |
Output is correct |
39 |
Correct |
1 ms |
2648 KB |
Output is correct |
40 |
Correct |
1 ms |
2648 KB |
Output is correct |
41 |
Correct |
1 ms |
2648 KB |
Output is correct |
42 |
Correct |
1 ms |
2648 KB |
Output is correct |
43 |
Execution timed out |
3089 ms |
4720 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |