#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) {
int dim = (a.size() - 1) + (b.size() - 1) + 1;
a.resize(dim);
b.resize(dim);
vector<ll> res(dim);
for (int i = 0; i < dim; i ++) {
for (int j = 0; j < dim; 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 'void dfs(int)':
circuit.cpp:49:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for (int i = 0; i < poly.size(); i ++) {
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Execution timed out |
3087 ms |
2944 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2780 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 |
2688 KB |
Output is correct |
6 |
Correct |
3 ms |
2648 KB |
Output is correct |
7 |
Correct |
3 ms |
2648 KB |
Output is correct |
8 |
Correct |
3 ms |
2648 KB |
Output is correct |
9 |
Correct |
3 ms |
2648 KB |
Output is correct |
10 |
Correct |
4 ms |
2904 KB |
Output is correct |
11 |
Correct |
3 ms |
2904 KB |
Output is correct |
12 |
Correct |
3 ms |
2648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Execution timed out |
3087 ms |
2944 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3045 ms |
5328 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3045 ms |
5328 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2780 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 |
2688 KB |
Output is correct |
6 |
Correct |
3 ms |
2648 KB |
Output is correct |
7 |
Correct |
3 ms |
2648 KB |
Output is correct |
8 |
Correct |
3 ms |
2648 KB |
Output is correct |
9 |
Correct |
3 ms |
2648 KB |
Output is correct |
10 |
Correct |
4 ms |
2904 KB |
Output is correct |
11 |
Correct |
3 ms |
2904 KB |
Output is correct |
12 |
Correct |
3 ms |
2648 KB |
Output is correct |
13 |
Execution timed out |
3045 ms |
5328 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Execution timed out |
3087 ms |
2944 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Execution timed out |
3087 ms |
2944 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |