#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include "circuit.h"
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 6e5 + 10;
const int mod = 1e9 + 2022;
int n, m;
vector <int> g[N];
int sz[N];
void dfs(int u) {
sz[u] = (u >= n ? 1 : g[u].size());
for (auto v: g[u]) {
dfs(v);
sz[u] = 1LL * sz[u] * sz[v] % mod;
}
}
int c[N], prf[N], suf[N];
int mul[N];
void fix(int u) {
int num = 0;
for (auto v: g[u]) c[++num] = v;
prf[0] = suf[num + 1] = 1;
for (int i = 1; i <= num; ++i) prf[i] = 1LL * prf[i - 1] * sz[c[i]] % mod;
for (int i = num; i >= 1; --i) suf[i] = 1LL * suf[i + 1] * sz[c[i]] % mod;
for (int i = 1; i <= num; ++i)
mul[c[i]] = 1LL * prf[i - 1] * suf[i + 1] % mod;
for (auto v: g[u]) fix(v);
}
int ans = 0;
void add(int& a, int b) {
a += b;
if (a >= mod) a -= mod;
if (a < 0) a += mod;
}
void Flip(int u) {
if (c[u]) add(ans, - mul[u]);
else add(ans, mul[u]);
c[u] ^= 1;
}
void init(int N, int M, vector<int> P, vector<int> A) {
n = N, m = M;
for (int i = 1; i < n + m; ++i) g[P[i]].push_back(i);
mul[0] = 1;
dfs(0);
fix(0);
memset(c, 0, sizeof(c));
for (int i = 1; i < n + m; ++i) mul[i] = 1LL * mul[i] * mul[P[i]] % mod;
for (int i = 0; i < m; ++i) if (A[i]) Flip(i + n);
}
int count_ways(int L, int R) {
for (int i = L; i <= R; ++i) Flip(i);
return ans;
}
//
//int main() {
// int N, M, Q;
// assert(3 == scanf("%d %d %d", &N, &M, &Q));
// std::vector<int> P(N + M), A(M);
// for (int i = 0; i < N + M; ++i) {
// assert(1 == scanf("%d", &P[i]));
// }
// for (int j = 0; j < M; ++j) {
// assert(1 == scanf("%d", &A[j]));
// }
// init(N, M, P, A);
//
// for (int i = 0; i < Q; ++i) {
// int L, R;
// assert(2 == scanf("%d %d", &L, &R));
// printf("%d\n", count_ways(L, R));
// }
// return 0;
//}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
16768 KB |
Output is correct |
2 |
Correct |
10 ms |
16720 KB |
Output is correct |
3 |
Correct |
9 ms |
16720 KB |
Output is correct |
4 |
Correct |
9 ms |
16720 KB |
Output is correct |
5 |
Correct |
9 ms |
16720 KB |
Output is correct |
6 |
Correct |
9 ms |
16700 KB |
Output is correct |
7 |
Correct |
9 ms |
16848 KB |
Output is correct |
8 |
Correct |
9 ms |
16720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
16720 KB |
Output is correct |
2 |
Correct |
9 ms |
16720 KB |
Output is correct |
3 |
Correct |
9 ms |
16720 KB |
Output is correct |
4 |
Correct |
10 ms |
16720 KB |
Output is correct |
5 |
Correct |
9 ms |
16720 KB |
Output is correct |
6 |
Correct |
9 ms |
16744 KB |
Output is correct |
7 |
Correct |
9 ms |
16732 KB |
Output is correct |
8 |
Correct |
9 ms |
16720 KB |
Output is correct |
9 |
Correct |
10 ms |
16720 KB |
Output is correct |
10 |
Correct |
9 ms |
16848 KB |
Output is correct |
11 |
Correct |
10 ms |
16868 KB |
Output is correct |
12 |
Correct |
9 ms |
16720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
16768 KB |
Output is correct |
2 |
Correct |
10 ms |
16720 KB |
Output is correct |
3 |
Correct |
9 ms |
16720 KB |
Output is correct |
4 |
Correct |
9 ms |
16720 KB |
Output is correct |
5 |
Correct |
9 ms |
16720 KB |
Output is correct |
6 |
Correct |
9 ms |
16700 KB |
Output is correct |
7 |
Correct |
9 ms |
16848 KB |
Output is correct |
8 |
Correct |
9 ms |
16720 KB |
Output is correct |
9 |
Correct |
9 ms |
16720 KB |
Output is correct |
10 |
Correct |
9 ms |
16720 KB |
Output is correct |
11 |
Correct |
9 ms |
16720 KB |
Output is correct |
12 |
Correct |
10 ms |
16720 KB |
Output is correct |
13 |
Correct |
9 ms |
16720 KB |
Output is correct |
14 |
Correct |
9 ms |
16744 KB |
Output is correct |
15 |
Correct |
9 ms |
16732 KB |
Output is correct |
16 |
Correct |
9 ms |
16720 KB |
Output is correct |
17 |
Correct |
10 ms |
16720 KB |
Output is correct |
18 |
Correct |
9 ms |
16848 KB |
Output is correct |
19 |
Correct |
10 ms |
16868 KB |
Output is correct |
20 |
Correct |
9 ms |
16720 KB |
Output is correct |
21 |
Correct |
11 ms |
16720 KB |
Output is correct |
22 |
Correct |
10 ms |
16784 KB |
Output is correct |
23 |
Correct |
8 ms |
16720 KB |
Output is correct |
24 |
Correct |
9 ms |
16800 KB |
Output is correct |
25 |
Correct |
10 ms |
16720 KB |
Output is correct |
26 |
Correct |
10 ms |
16720 KB |
Output is correct |
27 |
Correct |
9 ms |
16720 KB |
Output is correct |
28 |
Correct |
11 ms |
16780 KB |
Output is correct |
29 |
Correct |
11 ms |
16720 KB |
Output is correct |
30 |
Correct |
11 ms |
16720 KB |
Output is correct |
31 |
Correct |
9 ms |
16848 KB |
Output is correct |
32 |
Correct |
9 ms |
16720 KB |
Output is correct |
33 |
Correct |
9 ms |
16720 KB |
Output is correct |
34 |
Correct |
9 ms |
16760 KB |
Output is correct |
35 |
Correct |
9 ms |
16720 KB |
Output is correct |
36 |
Correct |
9 ms |
16848 KB |
Output is correct |
37 |
Correct |
10 ms |
16888 KB |
Output is correct |
38 |
Correct |
9 ms |
16848 KB |
Output is correct |
39 |
Correct |
9 ms |
16720 KB |
Output is correct |
40 |
Correct |
9 ms |
16720 KB |
Output is correct |
41 |
Correct |
11 ms |
16720 KB |
Output is correct |
42 |
Correct |
10 ms |
16720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
628 ms |
19004 KB |
Output is correct |
2 |
Correct |
901 ms |
21316 KB |
Output is correct |
3 |
Correct |
764 ms |
21320 KB |
Output is correct |
4 |
Correct |
836 ms |
21368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
628 ms |
19004 KB |
Output is correct |
2 |
Correct |
901 ms |
21316 KB |
Output is correct |
3 |
Correct |
764 ms |
21320 KB |
Output is correct |
4 |
Correct |
836 ms |
21368 KB |
Output is correct |
5 |
Execution timed out |
3030 ms |
19024 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
16720 KB |
Output is correct |
2 |
Correct |
9 ms |
16720 KB |
Output is correct |
3 |
Correct |
9 ms |
16720 KB |
Output is correct |
4 |
Correct |
10 ms |
16720 KB |
Output is correct |
5 |
Correct |
9 ms |
16720 KB |
Output is correct |
6 |
Correct |
9 ms |
16744 KB |
Output is correct |
7 |
Correct |
9 ms |
16732 KB |
Output is correct |
8 |
Correct |
9 ms |
16720 KB |
Output is correct |
9 |
Correct |
10 ms |
16720 KB |
Output is correct |
10 |
Correct |
9 ms |
16848 KB |
Output is correct |
11 |
Correct |
10 ms |
16868 KB |
Output is correct |
12 |
Correct |
9 ms |
16720 KB |
Output is correct |
13 |
Correct |
628 ms |
19004 KB |
Output is correct |
14 |
Correct |
901 ms |
21316 KB |
Output is correct |
15 |
Correct |
764 ms |
21320 KB |
Output is correct |
16 |
Correct |
836 ms |
21368 KB |
Output is correct |
17 |
Execution timed out |
3030 ms |
19024 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
16768 KB |
Output is correct |
2 |
Correct |
10 ms |
16720 KB |
Output is correct |
3 |
Correct |
9 ms |
16720 KB |
Output is correct |
4 |
Correct |
9 ms |
16720 KB |
Output is correct |
5 |
Correct |
9 ms |
16720 KB |
Output is correct |
6 |
Correct |
9 ms |
16700 KB |
Output is correct |
7 |
Correct |
9 ms |
16848 KB |
Output is correct |
8 |
Correct |
9 ms |
16720 KB |
Output is correct |
9 |
Correct |
9 ms |
16720 KB |
Output is correct |
10 |
Correct |
9 ms |
16720 KB |
Output is correct |
11 |
Correct |
9 ms |
16720 KB |
Output is correct |
12 |
Correct |
10 ms |
16720 KB |
Output is correct |
13 |
Correct |
9 ms |
16720 KB |
Output is correct |
14 |
Correct |
9 ms |
16744 KB |
Output is correct |
15 |
Correct |
9 ms |
16732 KB |
Output is correct |
16 |
Correct |
9 ms |
16720 KB |
Output is correct |
17 |
Correct |
10 ms |
16720 KB |
Output is correct |
18 |
Correct |
9 ms |
16848 KB |
Output is correct |
19 |
Correct |
10 ms |
16868 KB |
Output is correct |
20 |
Correct |
9 ms |
16720 KB |
Output is correct |
21 |
Correct |
11 ms |
16720 KB |
Output is correct |
22 |
Correct |
10 ms |
16784 KB |
Output is correct |
23 |
Correct |
8 ms |
16720 KB |
Output is correct |
24 |
Correct |
9 ms |
16800 KB |
Output is correct |
25 |
Correct |
10 ms |
16720 KB |
Output is correct |
26 |
Correct |
10 ms |
16720 KB |
Output is correct |
27 |
Correct |
9 ms |
16720 KB |
Output is correct |
28 |
Correct |
11 ms |
16780 KB |
Output is correct |
29 |
Correct |
11 ms |
16720 KB |
Output is correct |
30 |
Correct |
11 ms |
16720 KB |
Output is correct |
31 |
Correct |
9 ms |
16848 KB |
Output is correct |
32 |
Correct |
9 ms |
16720 KB |
Output is correct |
33 |
Correct |
9 ms |
16720 KB |
Output is correct |
34 |
Correct |
9 ms |
16760 KB |
Output is correct |
35 |
Correct |
9 ms |
16720 KB |
Output is correct |
36 |
Correct |
9 ms |
16848 KB |
Output is correct |
37 |
Correct |
10 ms |
16888 KB |
Output is correct |
38 |
Correct |
9 ms |
16848 KB |
Output is correct |
39 |
Correct |
9 ms |
16720 KB |
Output is correct |
40 |
Correct |
9 ms |
16720 KB |
Output is correct |
41 |
Correct |
11 ms |
16720 KB |
Output is correct |
42 |
Correct |
10 ms |
16720 KB |
Output is correct |
43 |
Correct |
977 ms |
16848 KB |
Output is correct |
44 |
Correct |
1377 ms |
16932 KB |
Output is correct |
45 |
Correct |
1482 ms |
16976 KB |
Output is correct |
46 |
Correct |
691 ms |
17060 KB |
Output is correct |
47 |
Correct |
1953 ms |
17076 KB |
Output is correct |
48 |
Correct |
1917 ms |
17104 KB |
Output is correct |
49 |
Correct |
2076 ms |
17088 KB |
Output is correct |
50 |
Correct |
2199 ms |
17104 KB |
Output is correct |
51 |
Correct |
2752 ms |
16944 KB |
Output is correct |
52 |
Correct |
1583 ms |
16848 KB |
Output is correct |
53 |
Correct |
584 ms |
17360 KB |
Output is correct |
54 |
Correct |
1904 ms |
17104 KB |
Output is correct |
55 |
Correct |
1732 ms |
16920 KB |
Output is correct |
56 |
Correct |
2075 ms |
16948 KB |
Output is correct |
57 |
Correct |
1734 ms |
16828 KB |
Output is correct |
58 |
Correct |
1987 ms |
17488 KB |
Output is correct |
59 |
Correct |
1493 ms |
17576 KB |
Output is correct |
60 |
Correct |
2751 ms |
17576 KB |
Output is correct |
61 |
Correct |
1269 ms |
16976 KB |
Output is correct |
62 |
Correct |
1630 ms |
16848 KB |
Output is correct |
63 |
Correct |
1749 ms |
16848 KB |
Output is correct |
64 |
Correct |
2021 ms |
16828 KB |
Output is correct |
65 |
Correct |
611 ms |
16848 KB |
Output is correct |
66 |
Correct |
1338 ms |
16976 KB |
Output is correct |
67 |
Correct |
1628 ms |
16976 KB |
Output is correct |
68 |
Execution timed out |
3032 ms |
16976 KB |
Time limit exceeded |
69 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
16768 KB |
Output is correct |
2 |
Correct |
10 ms |
16720 KB |
Output is correct |
3 |
Correct |
9 ms |
16720 KB |
Output is correct |
4 |
Correct |
9 ms |
16720 KB |
Output is correct |
5 |
Correct |
9 ms |
16720 KB |
Output is correct |
6 |
Correct |
9 ms |
16700 KB |
Output is correct |
7 |
Correct |
9 ms |
16848 KB |
Output is correct |
8 |
Correct |
9 ms |
16720 KB |
Output is correct |
9 |
Correct |
9 ms |
16720 KB |
Output is correct |
10 |
Correct |
9 ms |
16720 KB |
Output is correct |
11 |
Correct |
9 ms |
16720 KB |
Output is correct |
12 |
Correct |
10 ms |
16720 KB |
Output is correct |
13 |
Correct |
9 ms |
16720 KB |
Output is correct |
14 |
Correct |
9 ms |
16744 KB |
Output is correct |
15 |
Correct |
9 ms |
16732 KB |
Output is correct |
16 |
Correct |
9 ms |
16720 KB |
Output is correct |
17 |
Correct |
10 ms |
16720 KB |
Output is correct |
18 |
Correct |
9 ms |
16848 KB |
Output is correct |
19 |
Correct |
10 ms |
16868 KB |
Output is correct |
20 |
Correct |
9 ms |
16720 KB |
Output is correct |
21 |
Correct |
11 ms |
16720 KB |
Output is correct |
22 |
Correct |
10 ms |
16784 KB |
Output is correct |
23 |
Correct |
8 ms |
16720 KB |
Output is correct |
24 |
Correct |
9 ms |
16800 KB |
Output is correct |
25 |
Correct |
10 ms |
16720 KB |
Output is correct |
26 |
Correct |
10 ms |
16720 KB |
Output is correct |
27 |
Correct |
9 ms |
16720 KB |
Output is correct |
28 |
Correct |
11 ms |
16780 KB |
Output is correct |
29 |
Correct |
11 ms |
16720 KB |
Output is correct |
30 |
Correct |
11 ms |
16720 KB |
Output is correct |
31 |
Correct |
9 ms |
16848 KB |
Output is correct |
32 |
Correct |
9 ms |
16720 KB |
Output is correct |
33 |
Correct |
9 ms |
16720 KB |
Output is correct |
34 |
Correct |
9 ms |
16760 KB |
Output is correct |
35 |
Correct |
9 ms |
16720 KB |
Output is correct |
36 |
Correct |
9 ms |
16848 KB |
Output is correct |
37 |
Correct |
10 ms |
16888 KB |
Output is correct |
38 |
Correct |
9 ms |
16848 KB |
Output is correct |
39 |
Correct |
9 ms |
16720 KB |
Output is correct |
40 |
Correct |
9 ms |
16720 KB |
Output is correct |
41 |
Correct |
11 ms |
16720 KB |
Output is correct |
42 |
Correct |
10 ms |
16720 KB |
Output is correct |
43 |
Correct |
628 ms |
19004 KB |
Output is correct |
44 |
Correct |
901 ms |
21316 KB |
Output is correct |
45 |
Correct |
764 ms |
21320 KB |
Output is correct |
46 |
Correct |
836 ms |
21368 KB |
Output is correct |
47 |
Execution timed out |
3030 ms |
19024 KB |
Time limit exceeded |
48 |
Halted |
0 ms |
0 KB |
- |