#include "circuit.h"
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = (int)1e8 + 2022;
const int MAX = 1e6;
int par[MAX];
vector<int> childs[MAX];
int cntParams[MAX];
int nbInternes, nbFeuilles;
int coeff[MAX];
int iDeb[MAX], iFin[MAX];
int sum[MAX], sumCoeffs[MAX], lazy[MAX];
void pull(int node) {
sum[node] = sum[2 * node] + sum[2 * node + 1];
if (sum[node] >= MOD)
sum[node] -= MOD;
}
void push(int node) {
if (!lazy[node])
return;
sum[node] = sumCoeffs[node] - sum[node];
if (sum[node] < 0)
sum[node] += MOD;
if (iDeb[node] < iFin[node])
lazy[2 * node] ^= 1, lazy[2 * node + 1] ^= 1;
lazy[node] = 0;
}
void initSeg(int node, int l, int r, vector<signed> &valInit) {
iDeb[node] = l, iFin[node] = r;
if (l == r) {
sumCoeffs[node] = coeff[l];
sum[node] = valInit[l] * coeff[l];
return;
}
initSeg(2 * node, l, (l + r) / 2, valInit);
initSeg(2 * node + 1, (l + r) / 2 + 1, r, valInit);
pull(node);
sumCoeffs[node] = sumCoeffs[2 * node] + sumCoeffs[2 * node + 1];
if (sumCoeffs[node] >= MOD)
sumCoeffs[node] -= MOD;
}
void upd(int node, int l, int r) {
push(node);
if (l > iFin[node] or r < iDeb[node])
return;
if (l <= iDeb[node] and r >= iFin[node]) {
lazy[node] ^= 1;
push(node);
return;
}
upd(2 * node, l, r);
upd(2 * node + 1, l, r);
pull(node);
}
void setParams(int u) {
if (childs[u].empty()) {
cntParams[u] = 1;
return;
}
cntParams[u] = childs[u].size();
for (int v : childs[u]) {
setParams(v);
cntParams[u] = cntParams[u] * cntParams[v] % MOD;
}
}
void setCoeffs(int u, int bef) {
if (u >= nbInternes) {
coeff[u - nbInternes] = bef;
return;
}
int deg = childs[u].size();
vector<int> prefProd(deg + 1, 1), suffProd(deg + 1, 1);
for (int i = 0; i < deg; ++i)
prefProd[i + 1] = prefProd[i] * cntParams[childs[u][i]] % MOD;
for (int i = deg - 1; i >= 0; --i)
suffProd[i] = suffProd[i + 1] * cntParams[childs[u][i]] % MOD;
for (int i = 0; i < deg; ++i)
setCoeffs(childs[u][i], bef * prefProd[i] % MOD * suffProd[i + 1] % MOD);
}
void init(signed N, signed M, vector<signed> P, std::vector<signed> A) {
nbInternes = N, nbFeuilles = M;
int nbSommets = N + M;
for (int i = 1; i < nbSommets; ++i)
childs[P[i]].push_back(i);
setParams(0);
setCoeffs(0, 1);
}
signed count_ways(signed L, signed R) {
L -= nbInternes, R -= nbInternes;
upd(1, L, R);
return sum[1];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
15 ms |
23808 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
13 ms |
23760 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
15 ms |
23808 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
622 ms |
26344 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
622 ms |
26344 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
13 ms |
23760 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
15 ms |
23808 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
15 ms |
23808 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |