#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int mod = 1000002022;
int add(int x, int y) {
int z = x + y;
if (z >= mod) {
z -= mod;
}
return z;
}
int sub(int x, int y) {
int z = x - y;
if (z < 0) {
z += mod;
}
return z;
}
int mul(int x, int y) {
return (ll)x * y % mod;
}
int N, M, K;
vector<int> lazy, S, T;
void apply(int p, int v) {
if (v) {
S[p] = sub(T[p], S[p]);
lazy[p] ^= 1;
}
}
void push(int p) {
apply(p * 2 + 1, lazy[p]);
apply(p * 2 + 2, lazy[p]);
lazy[p] = 0;
}
void pull(int p) {
S[p] = add(S[p * 2 + 1], S[p * 2 + 2]);
}
void update(int p, int l, int r, int L, int R) {
if (R <= l || r <= L) {
return;
}
if (L <= l && r <= R) {
apply(p, 1);
return;
}
int m = (l + r + 1) / 2;
push(p);
update(p * 2 + 1, l, m, L, R);
update(p * 2 + 2, m, r, L, R);
pull(p);
}
void init(int n, int m, vector<int> P, vector<int> A) {
N = n, M = m;
vector<vector<int>> ch(N);
for (int i = 1; i < N + M; i++) {
ch[P[i]].push_back(i);
}
vector<int> tot(N + M);
for (int i = N; i < N + M; i++) {
tot[i] = 1;
}
for (int i = N - 1; i >= 0; i--) {
tot[i] = ch[i].size();
for (int j : ch[i]) {
tot[i] = mul(tot[i], tot[j]);
}
}
vector<int> f(N + M);
f[0] = 0;
for (int i = 0; i < N; i++) {
int q = ch[i].size();
vector<int> pre(q + 1);
pre[0] = 1;
for (int j = 0; j < q; j++) {
pre[j + 1] = mul(pre[j], tot[ch[i][j]]);
}
vector<int> suf(q + 1);
suf[q] = 1;
for (int j = q - 1; j >= 0; j--) {
suf[j] = mul(suf[j + 1], tot[ch[i][j]]);
}
for (int j = 0; j < q; j++) {
f[ch[i][j]] = mul(f[i], mul(pre[j], suf[j + 1]));
}
}
K = 2 << __lg(M);
S.resize(2 * K - 1);
T.resize(2 * K - 1);
lazy.resize(2 * K - 1);
for (int i = 0; i < M; i++) {
if (A[i] == 1) {
S[i + K - 1] = f[i + N];
}
T[i + K - 1] = f[i + N];
}
for (int i = K - 2; i >= 0; i--) {
S[i] = add(S[i * 2 + 1], S[i * 2 + 2]);
T[i] = add(T[i * 2 + 1], T[i * 2 + 2]);
}
}
int count_ways(int L, int R) {
update(0, 0, K, L - N, R - N + 1);
return S[0];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
420 ms |
4920 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
420 ms |
4920 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |