이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
constexpr ll MOD = 1000002022;
constexpr int MAXN = 2e5 + 5;
vector<int> adj[MAXN];
pair<ll, ll> dp[MAXN]; // attivo, spento
int N, M;
vector<int> A;
vector<int> P;
int PW;
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;
}
pair<ll, ll> merge(int a, int b) {
vector<ll> poly_a = {dp[a].second, dp[a].first};
vector<ll> poly_b = {dp[b].second, dp[b].first};
vector<ll> poly = mult(poly_a, poly_b);
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;
}
return {acceso, spento};
}
void init(int N, int M, vector<int> P, vector<int> A) {
:: N = N;
:: M = M;
:: A = A;
:: P = P;
:: PW = M;
for (int i = 1; i < N + M; i ++) {
adj[P[i]].push_back(i);
}
// dp 1 based
for (int i = 0; i < PW; i ++) dp[PW + i] = {A[i], A[i] ^ 1};
for (int i = PW - 1; i >= 1; i --) dp[i] = merge(2 * i, 2 * i + 1);
// for (int i = 1; i < 2 * PW; i ++) {
// cout << "seg i : " << i << " -> " << dp[i].first << " " << dp[i].second << '\n';
// }
}
int count_ways(int L, int R) {
int x = L + 1;
// cout << "L : " << L << " x : " << x << '\n';
A[L - N] ^= 1;
dp[x] = {A[L - N], A[L - N] ^ 1};
x /= 2;
while (x >= 1) {
dp[x] = merge(2 * x, 2 * x + 1);
x /= 2;
}
// for (int i = 1; i < 2 * PW; i ++) {
// cout << "seg i : " << i << " -> " << dp[i].first << " " << dp[i].second << '\n';
// }
return dp[1].first;
}
컴파일 시 표준 에러 (stderr) 메시지
circuit.cpp: In function 'std::vector<long long int> mult(std::vector<long long int>&, std::vector<long long int>&)':
circuit.cpp:18:23: 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 i = 0; i < a.size(); i ++) {
| ~~^~~~~~~~~~
circuit.cpp:19:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for (int j = 0; j < b.size(); j ++) {
| ~~^~~~~~~~~~
circuit.cpp: In function 'std::pair<long long int, long long int> merge(int, int)':
circuit.cpp:37:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | 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... |