#include <bits/stdc++.h>
using namespace std;
#define ll long long
constexpr ll MOD = 1000002022;
constexpr int MAXN = 1e5 + 5;
vector<int> adj[MAXN];
pair<ll, ll> dp[MAXN]; // attivo, spento
int N, M;
vector<int> A;
vector<ll> mult(vector<ll> &a, vector<ll> &b) { // b size è il minore ed è sempre 2
int dim = (a.size() - 1) + (b.size() - 1) + 1;
vector<ll> res(dim);
for (int i = 0; i < a.size(); i ++) {
for (int j = 0; j < b.size(); j ++) {
int sum = (i + j < dim) ? i + j : i + j - dim;
res[sum] += (a[i] * b[j]) % MOD;
res[sum] %= MOD;
}
}
return res;
}
void dfs(int u) {
if (u >= N) {
// cout << "u : " << u << '\n';
// cout << "source: " << dp[u].first << " " << dp[u].second << '\n';
return;
};
vector<ll> poly;
poly.push_back(1);
for (auto x : adj[u]) {
dfs(x);
auto [acceso, spento] = dp[x];
vector<ll> curr_poly = {spento, acceso};
poly = mult(poly, curr_poly);
}
ll acceso = 0;
ll spento = 0;
for (int i = 0; i < poly.size(); i ++) {
acceso += (poly[i] * i) % MOD;
acceso %= MOD;
spento += (poly[i] * (poly.size() - 1 - i)) % MOD;
spento %= MOD;
}
// cout << "u : " << u << '\n';
// cout << acceso << " " << spento << '\n';
dp[u] = {acceso, spento};
}
void init(int N, int M, vector<int> P, vector<int> A) {
:: N = N;
:: M = M;
:: A = A;
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 - N; i <= R - N; i ++) {
// cout << " i : " << i << '\n';
A[i] ^= 1;
}
// cout << "A : ";
// for (int i = 0; i < M; i ++) cout << A[i] << " ";
// cout << '\n';
for (int i = 0; i < M; i ++) {
dp[N + i] = {A[i], A[i] ^ 1};
}
dfs(0);
return dp[0].first;
}
Compilation message
circuit.cpp: In function 'std::vector<long long int> mult(std::vector<long long int>&, std::vector<long long int>&)':
circuit.cpp:17:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for (int i = 0; i < a.size(); i ++) {
| ~~^~~~~~~~~~
circuit.cpp:18:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | for (int j = 0; j < b.size(); j ++) {
| ~~^~~~~~~~~~
circuit.cpp: In function 'void dfs(int)':
circuit.cpp:47:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for (int i = 0; i < poly.size(); i ++) {
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2656 KB |
Output is correct |
3 |
Correct |
18 ms |
2904 KB |
Output is correct |
4 |
Correct |
19 ms |
2916 KB |
Output is correct |
5 |
Correct |
21 ms |
2904 KB |
Output is correct |
6 |
Correct |
19 ms |
2904 KB |
Output is correct |
7 |
Correct |
19 ms |
2904 KB |
Output is correct |
8 |
Correct |
19 ms |
2904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2784 KB |
Output is correct |
3 |
Correct |
2 ms |
2648 KB |
Output is correct |
4 |
Correct |
2 ms |
2648 KB |
Output is correct |
5 |
Correct |
2 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 |
2 ms |
2728 KB |
Output is correct |
10 |
Correct |
3 ms |
2904 KB |
Output is correct |
11 |
Correct |
2 ms |
2904 KB |
Output is correct |
12 |
Correct |
2 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 |
2656 KB |
Output is correct |
3 |
Correct |
18 ms |
2904 KB |
Output is correct |
4 |
Correct |
19 ms |
2916 KB |
Output is correct |
5 |
Correct |
21 ms |
2904 KB |
Output is correct |
6 |
Correct |
19 ms |
2904 KB |
Output is correct |
7 |
Correct |
19 ms |
2904 KB |
Output is correct |
8 |
Correct |
19 ms |
2904 KB |
Output is correct |
9 |
Correct |
1 ms |
2648 KB |
Output is correct |
10 |
Correct |
1 ms |
2784 KB |
Output is correct |
11 |
Correct |
2 ms |
2648 KB |
Output is correct |
12 |
Correct |
2 ms |
2648 KB |
Output is correct |
13 |
Correct |
2 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 |
2 ms |
2728 KB |
Output is correct |
18 |
Correct |
3 ms |
2904 KB |
Output is correct |
19 |
Correct |
2 ms |
2904 KB |
Output is correct |
20 |
Correct |
2 ms |
2648 KB |
Output is correct |
21 |
Correct |
2 ms |
2648 KB |
Output is correct |
22 |
Correct |
2 ms |
2648 KB |
Output is correct |
23 |
Correct |
2 ms |
2648 KB |
Output is correct |
24 |
Correct |
2 ms |
2648 KB |
Output is correct |
25 |
Correct |
2 ms |
2648 KB |
Output is correct |
26 |
Correct |
2 ms |
2648 KB |
Output is correct |
27 |
Correct |
2 ms |
2648 KB |
Output is correct |
28 |
Correct |
2 ms |
2648 KB |
Output is correct |
29 |
Correct |
19 ms |
2904 KB |
Output is correct |
30 |
Correct |
19 ms |
2904 KB |
Output is correct |
31 |
Correct |
2 ms |
2904 KB |
Output is correct |
32 |
Correct |
2 ms |
2656 KB |
Output is correct |
33 |
Correct |
2 ms |
2648 KB |
Output is correct |
34 |
Correct |
2 ms |
2648 KB |
Output is correct |
35 |
Correct |
5 ms |
2648 KB |
Output is correct |
36 |
Correct |
2 ms |
2904 KB |
Output is correct |
37 |
Correct |
19 ms |
3160 KB |
Output is correct |
38 |
Correct |
19 ms |
3156 KB |
Output is correct |
39 |
Correct |
2 ms |
2648 KB |
Output is correct |
40 |
Correct |
2 ms |
2648 KB |
Output is correct |
41 |
Correct |
2 ms |
2648 KB |
Output is correct |
42 |
Correct |
2 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3049 ms |
5328 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3049 ms |
5328 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 |
2784 KB |
Output is correct |
3 |
Correct |
2 ms |
2648 KB |
Output is correct |
4 |
Correct |
2 ms |
2648 KB |
Output is correct |
5 |
Correct |
2 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 |
2 ms |
2728 KB |
Output is correct |
10 |
Correct |
3 ms |
2904 KB |
Output is correct |
11 |
Correct |
2 ms |
2904 KB |
Output is correct |
12 |
Correct |
2 ms |
2648 KB |
Output is correct |
13 |
Execution timed out |
3049 ms |
5328 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 |
2656 KB |
Output is correct |
3 |
Correct |
18 ms |
2904 KB |
Output is correct |
4 |
Correct |
19 ms |
2916 KB |
Output is correct |
5 |
Correct |
21 ms |
2904 KB |
Output is correct |
6 |
Correct |
19 ms |
2904 KB |
Output is correct |
7 |
Correct |
19 ms |
2904 KB |
Output is correct |
8 |
Correct |
19 ms |
2904 KB |
Output is correct |
9 |
Correct |
1 ms |
2648 KB |
Output is correct |
10 |
Correct |
1 ms |
2784 KB |
Output is correct |
11 |
Correct |
2 ms |
2648 KB |
Output is correct |
12 |
Correct |
2 ms |
2648 KB |
Output is correct |
13 |
Correct |
2 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 |
2 ms |
2728 KB |
Output is correct |
18 |
Correct |
3 ms |
2904 KB |
Output is correct |
19 |
Correct |
2 ms |
2904 KB |
Output is correct |
20 |
Correct |
2 ms |
2648 KB |
Output is correct |
21 |
Correct |
2 ms |
2648 KB |
Output is correct |
22 |
Correct |
2 ms |
2648 KB |
Output is correct |
23 |
Correct |
2 ms |
2648 KB |
Output is correct |
24 |
Correct |
2 ms |
2648 KB |
Output is correct |
25 |
Correct |
2 ms |
2648 KB |
Output is correct |
26 |
Correct |
2 ms |
2648 KB |
Output is correct |
27 |
Correct |
2 ms |
2648 KB |
Output is correct |
28 |
Correct |
2 ms |
2648 KB |
Output is correct |
29 |
Correct |
19 ms |
2904 KB |
Output is correct |
30 |
Correct |
19 ms |
2904 KB |
Output is correct |
31 |
Correct |
2 ms |
2904 KB |
Output is correct |
32 |
Correct |
2 ms |
2656 KB |
Output is correct |
33 |
Correct |
2 ms |
2648 KB |
Output is correct |
34 |
Correct |
2 ms |
2648 KB |
Output is correct |
35 |
Correct |
5 ms |
2648 KB |
Output is correct |
36 |
Correct |
2 ms |
2904 KB |
Output is correct |
37 |
Correct |
19 ms |
3160 KB |
Output is correct |
38 |
Correct |
19 ms |
3156 KB |
Output is correct |
39 |
Correct |
2 ms |
2648 KB |
Output is correct |
40 |
Correct |
2 ms |
2648 KB |
Output is correct |
41 |
Correct |
2 ms |
2648 KB |
Output is correct |
42 |
Correct |
2 ms |
2652 KB |
Output is correct |
43 |
Execution timed out |
3009 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 |
2656 KB |
Output is correct |
3 |
Correct |
18 ms |
2904 KB |
Output is correct |
4 |
Correct |
19 ms |
2916 KB |
Output is correct |
5 |
Correct |
21 ms |
2904 KB |
Output is correct |
6 |
Correct |
19 ms |
2904 KB |
Output is correct |
7 |
Correct |
19 ms |
2904 KB |
Output is correct |
8 |
Correct |
19 ms |
2904 KB |
Output is correct |
9 |
Correct |
1 ms |
2648 KB |
Output is correct |
10 |
Correct |
1 ms |
2784 KB |
Output is correct |
11 |
Correct |
2 ms |
2648 KB |
Output is correct |
12 |
Correct |
2 ms |
2648 KB |
Output is correct |
13 |
Correct |
2 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 |
2 ms |
2728 KB |
Output is correct |
18 |
Correct |
3 ms |
2904 KB |
Output is correct |
19 |
Correct |
2 ms |
2904 KB |
Output is correct |
20 |
Correct |
2 ms |
2648 KB |
Output is correct |
21 |
Correct |
2 ms |
2648 KB |
Output is correct |
22 |
Correct |
2 ms |
2648 KB |
Output is correct |
23 |
Correct |
2 ms |
2648 KB |
Output is correct |
24 |
Correct |
2 ms |
2648 KB |
Output is correct |
25 |
Correct |
2 ms |
2648 KB |
Output is correct |
26 |
Correct |
2 ms |
2648 KB |
Output is correct |
27 |
Correct |
2 ms |
2648 KB |
Output is correct |
28 |
Correct |
2 ms |
2648 KB |
Output is correct |
29 |
Correct |
19 ms |
2904 KB |
Output is correct |
30 |
Correct |
19 ms |
2904 KB |
Output is correct |
31 |
Correct |
2 ms |
2904 KB |
Output is correct |
32 |
Correct |
2 ms |
2656 KB |
Output is correct |
33 |
Correct |
2 ms |
2648 KB |
Output is correct |
34 |
Correct |
2 ms |
2648 KB |
Output is correct |
35 |
Correct |
5 ms |
2648 KB |
Output is correct |
36 |
Correct |
2 ms |
2904 KB |
Output is correct |
37 |
Correct |
19 ms |
3160 KB |
Output is correct |
38 |
Correct |
19 ms |
3156 KB |
Output is correct |
39 |
Correct |
2 ms |
2648 KB |
Output is correct |
40 |
Correct |
2 ms |
2648 KB |
Output is correct |
41 |
Correct |
2 ms |
2648 KB |
Output is correct |
42 |
Correct |
2 ms |
2652 KB |
Output is correct |
43 |
Execution timed out |
3049 ms |
5328 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |