#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
const int mod = 100002022;
int n, m;
vector<int> E[200005];
int S[200005], C[200005];
void dfs1(int x) {
S[x] = max(1, int(E[x].size()));
for (int i : E[x]) {
dfs1(i);
S[x] = 1ll * S[x] * S[i] % mod;
}
}
void dfs2(int x) {
// printf("S[%d] = %d, C[%d] = %d\n", x, S[x], x, C[x]);
vector<int> R(E[x].size());
R.push_back(1);
for (int i = E[x].size(); i--; ) {
R[i] = 1ll * R[i + 1] * S[E[x][i]] % mod;
}
int L = 1;
for (int i = 0; i < int(E[x].size()); ++i) {
C[E[x][i]] = 1ll * L * R[i + 1] % mod * C[x] % mod;
dfs2(E[x][i]);
L = 1ll * L * S[E[x][i]] % mod;
}
}
int add(int x, int y) {
x += y;
if (x >= mod) return x - mod;
return x;
}
vector<int> A;
int seg[1 << 18], rev[1 << 18], lz[1 << 18];
void init(int i, int s, int e) {
if (s == e) {
seg[i] = 0;
rev[i] = C[s];
lz[i] = 0;
if (A[s - n]) swap(seg[i], rev[i]);
return;
}
int m = (s + e) / 2;
init(i + i, s, m);
init(i + i + 1, m + 1, e);
seg[i] = add(seg[i + i], seg[i + i + 1]);
rev[i] = add(rev[i + i], rev[i + i + 1]);
lz[i] = 0;
}
void update(int i, int s, int e, int x, int y) {
if (e < x || y < s) return;
if (x <= s && e <= y) {
swap(seg[i], rev[i]);
lz[i] ^= 1;
return;
}
int m = (s + e) / 2;
if (lz[i]) {
lz[i] = 0;
swap(seg[i + i], rev[i + i]);
lz[i + i] ^= 1;
swap(seg[i + i + 1], rev[i + i + 1]);
lz[i + i + 1] ^= 1;
}
update(i + i, s, m, x, y);
update(i + i + 1, m + 1, e, x, y);
seg[i] = add(seg[i + i], seg[i + i + 1]);
rev[i] = add(rev[i + i], rev[i + i + 1]);
}
void init(int N, int M, vector<int> P, vector<int> A) {
n = N;
m = M;
for (int i = 1; i < n + m; ++i) E[P[i]].push_back(i);
dfs1(0);
C[0] = 1;
dfs2(0);
::A = A;
init(1, n, n + m - 1);
}
int count_ways(int L, int R) {
update(1, n, n + m - 1, L, R);
return seg[1];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5072 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
5072 KB |
Output is correct |
4 |
Correct |
3 ms |
5072 KB |
Output is correct |
5 |
Correct |
3 ms |
5072 KB |
Output is correct |
6 |
Correct |
3 ms |
5072 KB |
Output is correct |
7 |
Correct |
3 ms |
5072 KB |
Output is correct |
8 |
Correct |
3 ms |
5072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Incorrect |
3 ms |
4964 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '57429070' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5072 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
5072 KB |
Output is correct |
4 |
Correct |
3 ms |
5072 KB |
Output is correct |
5 |
Correct |
3 ms |
5072 KB |
Output is correct |
6 |
Correct |
3 ms |
5072 KB |
Output is correct |
7 |
Correct |
3 ms |
5072 KB |
Output is correct |
8 |
Correct |
3 ms |
5072 KB |
Output is correct |
9 |
Correct |
3 ms |
4944 KB |
Output is correct |
10 |
Incorrect |
3 ms |
4964 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '57429070' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
363 ms |
8144 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '16463726' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
363 ms |
8144 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '16463726' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Incorrect |
3 ms |
4964 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '57429070' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5072 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
5072 KB |
Output is correct |
4 |
Correct |
3 ms |
5072 KB |
Output is correct |
5 |
Correct |
3 ms |
5072 KB |
Output is correct |
6 |
Correct |
3 ms |
5072 KB |
Output is correct |
7 |
Correct |
3 ms |
5072 KB |
Output is correct |
8 |
Correct |
3 ms |
5072 KB |
Output is correct |
9 |
Correct |
3 ms |
4944 KB |
Output is correct |
10 |
Incorrect |
3 ms |
4964 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '57429070' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5072 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
5072 KB |
Output is correct |
4 |
Correct |
3 ms |
5072 KB |
Output is correct |
5 |
Correct |
3 ms |
5072 KB |
Output is correct |
6 |
Correct |
3 ms |
5072 KB |
Output is correct |
7 |
Correct |
3 ms |
5072 KB |
Output is correct |
8 |
Correct |
3 ms |
5072 KB |
Output is correct |
9 |
Correct |
3 ms |
4944 KB |
Output is correct |
10 |
Incorrect |
3 ms |
4964 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '57429070' |
11 |
Halted |
0 ms |
0 KB |
- |