#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000002022;
int ckadd(int a, int b) {
return a + b >= MOD ? a + b - MOD : a + b;
}
int ckmul(int a, int b) {
return a * 1LL * b % MOD;
}
int ckpower(int a, int n) {
int res = 1;
while (n) {
if (n & 1)
res = ckmul(res, a);
a = ckmul(a, a);
n >>= 1;
}
return res;
}
int ckdiv(int a, int b) {
return ckmul(a, ckpower(b, MOD - 2));
}
const int N = (int)2e5 + 6;
int n, m;
int a[N];
int par[N];
int deg[N];
int ANS[N];
bool vis[N];
int solve(int v) {
for (int i = 0; i < n; i++) vis[i] = false;
while (v != -1) {
if (v < n) vis[v] = true;
v = par[v];
}
int prod = 1;
for (int i = 0; i < n; i++) if (!vis[i]) {
prod = ckmul(prod, deg[i]);
}
return prod;
}
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
n = N; m = M;
for (int i = n; i < n + m; i++) a[i] = A[i - n];
for (int i = 0; i < n + m; i++) par[i] = P[i];
for (int i = 1; i < n + m; i++) deg[par[i]]++;
for (int i = n; i < n + m; i++) ANS[i] = solve(i);
}
int count_ways(int L, int R) {
for (int i = L; i <= R; i++) a[i] = 1 - a[i];
int ans = 0;
for (int i = n; i < n + m; i++) if (a[i] == 1) {
ans = ckadd(ans, ANS[i]);
}
return ans;
}
/*
3 4 3
-1 0 1 2 1 1 0
1 0 1 0
3 4
4 5
3 6
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
336 KB |
Output is correct |
4 |
Correct |
0 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
336 KB |
Output is correct |
4 |
Correct |
2 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
352 KB |
Output is correct |
6 |
Correct |
3 ms |
336 KB |
Output is correct |
7 |
Correct |
5 ms |
292 KB |
Output is correct |
8 |
Correct |
5 ms |
360 KB |
Output is correct |
9 |
Correct |
5 ms |
336 KB |
Output is correct |
10 |
Correct |
4 ms |
336 KB |
Output is correct |
11 |
Correct |
4 ms |
336 KB |
Output is correct |
12 |
Correct |
4 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
336 KB |
Output is correct |
4 |
Correct |
0 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
2 ms |
336 KB |
Output is correct |
12 |
Correct |
2 ms |
336 KB |
Output is correct |
13 |
Correct |
2 ms |
352 KB |
Output is correct |
14 |
Correct |
3 ms |
336 KB |
Output is correct |
15 |
Correct |
5 ms |
292 KB |
Output is correct |
16 |
Correct |
5 ms |
360 KB |
Output is correct |
17 |
Correct |
5 ms |
336 KB |
Output is correct |
18 |
Correct |
4 ms |
336 KB |
Output is correct |
19 |
Correct |
4 ms |
336 KB |
Output is correct |
20 |
Correct |
4 ms |
336 KB |
Output is correct |
21 |
Correct |
4 ms |
336 KB |
Output is correct |
22 |
Correct |
3 ms |
336 KB |
Output is correct |
23 |
Correct |
3 ms |
336 KB |
Output is correct |
24 |
Correct |
5 ms |
360 KB |
Output is correct |
25 |
Correct |
5 ms |
336 KB |
Output is correct |
26 |
Correct |
5 ms |
336 KB |
Output is correct |
27 |
Correct |
5 ms |
336 KB |
Output is correct |
28 |
Correct |
6 ms |
360 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
0 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
208 KB |
Output is correct |
32 |
Correct |
6 ms |
336 KB |
Output is correct |
33 |
Correct |
3 ms |
336 KB |
Output is correct |
34 |
Correct |
2 ms |
336 KB |
Output is correct |
35 |
Correct |
0 ms |
336 KB |
Output is correct |
36 |
Correct |
4 ms |
336 KB |
Output is correct |
37 |
Correct |
3 ms |
336 KB |
Output is correct |
38 |
Correct |
3 ms |
336 KB |
Output is correct |
39 |
Correct |
2 ms |
336 KB |
Output is correct |
40 |
Correct |
2 ms |
336 KB |
Output is correct |
41 |
Correct |
2 ms |
336 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3042 ms |
1920 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3042 ms |
1920 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
336 KB |
Output is correct |
4 |
Correct |
2 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
352 KB |
Output is correct |
6 |
Correct |
3 ms |
336 KB |
Output is correct |
7 |
Correct |
5 ms |
292 KB |
Output is correct |
8 |
Correct |
5 ms |
360 KB |
Output is correct |
9 |
Correct |
5 ms |
336 KB |
Output is correct |
10 |
Correct |
4 ms |
336 KB |
Output is correct |
11 |
Correct |
4 ms |
336 KB |
Output is correct |
12 |
Correct |
4 ms |
336 KB |
Output is correct |
13 |
Execution timed out |
3042 ms |
1920 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
336 KB |
Output is correct |
4 |
Correct |
0 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
2 ms |
336 KB |
Output is correct |
12 |
Correct |
2 ms |
336 KB |
Output is correct |
13 |
Correct |
2 ms |
352 KB |
Output is correct |
14 |
Correct |
3 ms |
336 KB |
Output is correct |
15 |
Correct |
5 ms |
292 KB |
Output is correct |
16 |
Correct |
5 ms |
360 KB |
Output is correct |
17 |
Correct |
5 ms |
336 KB |
Output is correct |
18 |
Correct |
4 ms |
336 KB |
Output is correct |
19 |
Correct |
4 ms |
336 KB |
Output is correct |
20 |
Correct |
4 ms |
336 KB |
Output is correct |
21 |
Correct |
4 ms |
336 KB |
Output is correct |
22 |
Correct |
3 ms |
336 KB |
Output is correct |
23 |
Correct |
3 ms |
336 KB |
Output is correct |
24 |
Correct |
5 ms |
360 KB |
Output is correct |
25 |
Correct |
5 ms |
336 KB |
Output is correct |
26 |
Correct |
5 ms |
336 KB |
Output is correct |
27 |
Correct |
5 ms |
336 KB |
Output is correct |
28 |
Correct |
6 ms |
360 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
0 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
208 KB |
Output is correct |
32 |
Correct |
6 ms |
336 KB |
Output is correct |
33 |
Correct |
3 ms |
336 KB |
Output is correct |
34 |
Correct |
2 ms |
336 KB |
Output is correct |
35 |
Correct |
0 ms |
336 KB |
Output is correct |
36 |
Correct |
4 ms |
336 KB |
Output is correct |
37 |
Correct |
3 ms |
336 KB |
Output is correct |
38 |
Correct |
3 ms |
336 KB |
Output is correct |
39 |
Correct |
2 ms |
336 KB |
Output is correct |
40 |
Correct |
2 ms |
336 KB |
Output is correct |
41 |
Correct |
2 ms |
336 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
43 |
Correct |
1182 ms |
436 KB |
Output is correct |
44 |
Correct |
1407 ms |
432 KB |
Output is correct |
45 |
Correct |
1871 ms |
336 KB |
Output is correct |
46 |
Correct |
2067 ms |
504 KB |
Output is correct |
47 |
Correct |
2551 ms |
508 KB |
Output is correct |
48 |
Correct |
2605 ms |
628 KB |
Output is correct |
49 |
Correct |
2699 ms |
504 KB |
Output is correct |
50 |
Correct |
1705 ms |
424 KB |
Output is correct |
51 |
Correct |
2597 ms |
432 KB |
Output is correct |
52 |
Correct |
2474 ms |
336 KB |
Output is correct |
53 |
Correct |
748 ms |
300 KB |
Output is correct |
54 |
Correct |
2712 ms |
504 KB |
Output is correct |
55 |
Correct |
2650 ms |
592 KB |
Output is correct |
56 |
Correct |
2556 ms |
456 KB |
Output is correct |
57 |
Correct |
2475 ms |
336 KB |
Output is correct |
58 |
Correct |
2578 ms |
512 KB |
Output is correct |
59 |
Correct |
2289 ms |
516 KB |
Output is correct |
60 |
Correct |
2746 ms |
516 KB |
Output is correct |
61 |
Correct |
1604 ms |
544 KB |
Output is correct |
62 |
Correct |
1976 ms |
424 KB |
Output is correct |
63 |
Correct |
2013 ms |
336 KB |
Output is correct |
64 |
Correct |
2524 ms |
336 KB |
Output is correct |
65 |
Correct |
752 ms |
464 KB |
Output is correct |
66 |
Correct |
2125 ms |
480 KB |
Output is correct |
67 |
Correct |
2291 ms |
464 KB |
Output is correct |
68 |
Correct |
2187 ms |
472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
336 KB |
Output is correct |
4 |
Correct |
0 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
2 ms |
336 KB |
Output is correct |
12 |
Correct |
2 ms |
336 KB |
Output is correct |
13 |
Correct |
2 ms |
352 KB |
Output is correct |
14 |
Correct |
3 ms |
336 KB |
Output is correct |
15 |
Correct |
5 ms |
292 KB |
Output is correct |
16 |
Correct |
5 ms |
360 KB |
Output is correct |
17 |
Correct |
5 ms |
336 KB |
Output is correct |
18 |
Correct |
4 ms |
336 KB |
Output is correct |
19 |
Correct |
4 ms |
336 KB |
Output is correct |
20 |
Correct |
4 ms |
336 KB |
Output is correct |
21 |
Correct |
4 ms |
336 KB |
Output is correct |
22 |
Correct |
3 ms |
336 KB |
Output is correct |
23 |
Correct |
3 ms |
336 KB |
Output is correct |
24 |
Correct |
5 ms |
360 KB |
Output is correct |
25 |
Correct |
5 ms |
336 KB |
Output is correct |
26 |
Correct |
5 ms |
336 KB |
Output is correct |
27 |
Correct |
5 ms |
336 KB |
Output is correct |
28 |
Correct |
6 ms |
360 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
0 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
208 KB |
Output is correct |
32 |
Correct |
6 ms |
336 KB |
Output is correct |
33 |
Correct |
3 ms |
336 KB |
Output is correct |
34 |
Correct |
2 ms |
336 KB |
Output is correct |
35 |
Correct |
0 ms |
336 KB |
Output is correct |
36 |
Correct |
4 ms |
336 KB |
Output is correct |
37 |
Correct |
3 ms |
336 KB |
Output is correct |
38 |
Correct |
3 ms |
336 KB |
Output is correct |
39 |
Correct |
2 ms |
336 KB |
Output is correct |
40 |
Correct |
2 ms |
336 KB |
Output is correct |
41 |
Correct |
2 ms |
336 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
43 |
Execution timed out |
3042 ms |
1920 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |