This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |