#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
using i32 = int;
#define int long long
#define len(x) ((int)(x.size()))
template<typename T>
using vec = vector<T>;
template<typename T>
using graph = vec<vec<T>>;
vec<int> cur;
graph<int> g;
int n, m;
#define mod 1000002022
int sum(int a, int b) {
return (a + b) - (a + b >= mod ? mod : 0);
}
int sub(int a, int b) {
return (a - b + mod) - ((a - b + mod) >= mod ? mod : 0);
}
int mult(int a, int b) {
return (a * b) % mod;
}
int bin_pow(int a, int b) {
int r = 1;
while (b) {
if (b & 1)
r = mult(r, a);
a = mult(a, a);
b >>= 1;
}
return r;
}
const int maxN = 1e5 + 5;
struct vertex {
int length;
int cur_sum;
};
vertex stree[maxN * 4];
bool pushes[maxN * 4];
void init() {
memset(stree, 0, sizeof(stree));
memset(pushes, 0, sizeof(pushes));
}
void push(int v, int tl, int tr) {
if (!pushes[v]) return;
if (tl != tr) {
pushes[v * 2] ^= 1;
pushes[v * 2 + 1] ^= 1;
stree[v * 2].cur_sum = sub(stree[v * 2].length, stree[v * 2].cur_sum);
stree[v * 2 + 1].cur_sum = sub(stree[v * 2 + 1].length, stree[v * 2 + 1].cur_sum);
}
pushes[v] = false;
}
void build(int v, int tl, int tr, vec<int>& length) {
if (tl == tr) {
stree[v].length = length[tl];
stree[v].cur_sum = 0;
return;
}
int tm = (tl + tr) / 2;
build(v * 2, tl, tm, length);
build(v * 2 + 1, tm + 1, tr, length);
stree[v].length = sum(stree[v * 2].length, stree[v * 2 + 1].length);
stree[v].cur_sum = 0;
}
void update(int v, int tl, int tr, int l, int r) {
push(v, tl, tr);
if (tl == l and tr == r) {
stree[v].cur_sum = sub(stree[v].length, stree[v].cur_sum);
pushes[v] ^= 1;
push(v, tl, tr);
return;
}
int tm = (tl + tr) / 2;
if (r <= tm) {
update(v * 2, tl, tm, l, r);
} else if (l > tm) {
update(v * 2 + 1, tm + 1, tr, l, r);
} else {
update(v * 2, tl, tm, l, tm);
update(v * 2 + 1, tm + 1, tr, tm + 1, r);
}
stree[v].cur_sum = sum(stree[v * 2].cur_sum, stree[v * 2 + 1].cur_sum);
stree[v].length = sum(stree[v * 2].length, stree[v * 2 + 1].length);
}
int get(int v, int tl, int tr, int l, int r) {
push(v, tl, tr);
if (tl == l and tr == r) {
return stree[v].cur_sum;
}
int tm = (tl + tr) / 2;
if (r <= tm) {
return get(v * 2, tl, tm, l, r);
} else if (l > tm) {
return get(v * 2 + 1, tm + 1, tr, l, r);
} else {
return sum(get(v * 2, tl, tm, l, tm), get(v * 2 + 1, tm + 1, tr, tm + 1, r));
}
}
void init(i32 N, i32 M, std::vector<i32> P, std::vector<i32> A) {
n = N;
m = M;
g.resize(n + m);
for (int i = 1; i < len(P); i++) {
g[P[i]].push_back(i);
}
for (int i = 0; i < m; i++) {
cur.push_back(A[i]);
}
int depth = 0;
vec<int> d(n + m, 0);
function<void(int)> dfs = [&](int v) {
d[v] = depth;
for (auto u: g[v]) {
depth++;
dfs(u);
depth--;
}
};
dfs(0);
init();
vec<int> dists(m);
for (int i = n; i < m + n; i++) {
dists[i - n] = bin_pow(2, n - d[i]);
}
build(1, 0, m - 1, dists);
for (int i = 0; i < m; i++) {
if (cur[i] == 1) {
update(1, 0, m - 1, i, i);
}
}
}
i32 count_ways(i32 L, i32 R) {
L -= n;
R -= n;
update(1, 0, m - 1, L, R);
int cur_sum = get(1, 0, m - 1, 0, m - 1);
return cur_sum;
}
//422283126
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
7000 KB |
Output is correct |
2 |
Correct |
1 ms |
7000 KB |
Output is correct |
3 |
Correct |
1 ms |
7000 KB |
Output is correct |
4 |
Correct |
1 ms |
7000 KB |
Output is correct |
5 |
Correct |
1 ms |
7000 KB |
Output is correct |
6 |
Correct |
1 ms |
7000 KB |
Output is correct |
7 |
Correct |
1 ms |
7000 KB |
Output is correct |
8 |
Correct |
1 ms |
7000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
7000 KB |
Output is correct |
2 |
Correct |
1 ms |
7000 KB |
Output is correct |
3 |
Correct |
2 ms |
7000 KB |
Output is correct |
4 |
Correct |
1 ms |
7000 KB |
Output is correct |
5 |
Correct |
1 ms |
7000 KB |
Output is correct |
6 |
Correct |
1 ms |
7000 KB |
Output is correct |
7 |
Correct |
1 ms |
7000 KB |
Output is correct |
8 |
Correct |
1 ms |
7000 KB |
Output is correct |
9 |
Correct |
1 ms |
7000 KB |
Output is correct |
10 |
Correct |
1 ms |
7256 KB |
Output is correct |
11 |
Correct |
1 ms |
7256 KB |
Output is correct |
12 |
Correct |
2 ms |
7000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
7000 KB |
Output is correct |
2 |
Correct |
1 ms |
7000 KB |
Output is correct |
3 |
Correct |
1 ms |
7000 KB |
Output is correct |
4 |
Correct |
1 ms |
7000 KB |
Output is correct |
5 |
Correct |
1 ms |
7000 KB |
Output is correct |
6 |
Correct |
1 ms |
7000 KB |
Output is correct |
7 |
Correct |
1 ms |
7000 KB |
Output is correct |
8 |
Correct |
1 ms |
7000 KB |
Output is correct |
9 |
Correct |
1 ms |
7000 KB |
Output is correct |
10 |
Correct |
1 ms |
7000 KB |
Output is correct |
11 |
Correct |
2 ms |
7000 KB |
Output is correct |
12 |
Correct |
1 ms |
7000 KB |
Output is correct |
13 |
Correct |
1 ms |
7000 KB |
Output is correct |
14 |
Correct |
1 ms |
7000 KB |
Output is correct |
15 |
Correct |
1 ms |
7000 KB |
Output is correct |
16 |
Correct |
1 ms |
7000 KB |
Output is correct |
17 |
Correct |
1 ms |
7000 KB |
Output is correct |
18 |
Correct |
1 ms |
7256 KB |
Output is correct |
19 |
Correct |
1 ms |
7256 KB |
Output is correct |
20 |
Correct |
2 ms |
7000 KB |
Output is correct |
21 |
Incorrect |
1 ms |
6960 KB |
1st lines differ - on the 1st token, expected: '759476520', found: '833967706' |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
382 ms |
11484 KB |
Output is correct |
2 |
Correct |
568 ms |
16200 KB |
Output is correct |
3 |
Correct |
601 ms |
15976 KB |
Output is correct |
4 |
Correct |
534 ms |
15832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
382 ms |
11484 KB |
Output is correct |
2 |
Correct |
568 ms |
16200 KB |
Output is correct |
3 |
Correct |
601 ms |
15976 KB |
Output is correct |
4 |
Correct |
534 ms |
15832 KB |
Output is correct |
5 |
Correct |
454 ms |
11484 KB |
Output is correct |
6 |
Correct |
539 ms |
15984 KB |
Output is correct |
7 |
Correct |
561 ms |
15832 KB |
Output is correct |
8 |
Correct |
598 ms |
15824 KB |
Output is correct |
9 |
Correct |
256 ms |
7348 KB |
Output is correct |
10 |
Correct |
524 ms |
7512 KB |
Output is correct |
11 |
Correct |
577 ms |
7512 KB |
Output is correct |
12 |
Correct |
541 ms |
7512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
7000 KB |
Output is correct |
2 |
Correct |
1 ms |
7000 KB |
Output is correct |
3 |
Correct |
2 ms |
7000 KB |
Output is correct |
4 |
Correct |
1 ms |
7000 KB |
Output is correct |
5 |
Correct |
1 ms |
7000 KB |
Output is correct |
6 |
Correct |
1 ms |
7000 KB |
Output is correct |
7 |
Correct |
1 ms |
7000 KB |
Output is correct |
8 |
Correct |
1 ms |
7000 KB |
Output is correct |
9 |
Correct |
1 ms |
7000 KB |
Output is correct |
10 |
Correct |
1 ms |
7256 KB |
Output is correct |
11 |
Correct |
1 ms |
7256 KB |
Output is correct |
12 |
Correct |
2 ms |
7000 KB |
Output is correct |
13 |
Correct |
382 ms |
11484 KB |
Output is correct |
14 |
Correct |
568 ms |
16200 KB |
Output is correct |
15 |
Correct |
601 ms |
15976 KB |
Output is correct |
16 |
Correct |
534 ms |
15832 KB |
Output is correct |
17 |
Correct |
454 ms |
11484 KB |
Output is correct |
18 |
Correct |
539 ms |
15984 KB |
Output is correct |
19 |
Correct |
561 ms |
15832 KB |
Output is correct |
20 |
Correct |
598 ms |
15824 KB |
Output is correct |
21 |
Correct |
256 ms |
7348 KB |
Output is correct |
22 |
Correct |
524 ms |
7512 KB |
Output is correct |
23 |
Correct |
577 ms |
7512 KB |
Output is correct |
24 |
Correct |
541 ms |
7512 KB |
Output is correct |
25 |
Correct |
555 ms |
20172 KB |
Output is correct |
26 |
Correct |
612 ms |
20324 KB |
Output is correct |
27 |
Correct |
611 ms |
20428 KB |
Output is correct |
28 |
Correct |
494 ms |
20428 KB |
Output is correct |
29 |
Correct |
608 ms |
26580 KB |
Output is correct |
30 |
Correct |
601 ms |
26580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
7000 KB |
Output is correct |
2 |
Correct |
1 ms |
7000 KB |
Output is correct |
3 |
Correct |
1 ms |
7000 KB |
Output is correct |
4 |
Correct |
1 ms |
7000 KB |
Output is correct |
5 |
Correct |
1 ms |
7000 KB |
Output is correct |
6 |
Correct |
1 ms |
7000 KB |
Output is correct |
7 |
Correct |
1 ms |
7000 KB |
Output is correct |
8 |
Correct |
1 ms |
7000 KB |
Output is correct |
9 |
Correct |
1 ms |
7000 KB |
Output is correct |
10 |
Correct |
1 ms |
7000 KB |
Output is correct |
11 |
Correct |
2 ms |
7000 KB |
Output is correct |
12 |
Correct |
1 ms |
7000 KB |
Output is correct |
13 |
Correct |
1 ms |
7000 KB |
Output is correct |
14 |
Correct |
1 ms |
7000 KB |
Output is correct |
15 |
Correct |
1 ms |
7000 KB |
Output is correct |
16 |
Correct |
1 ms |
7000 KB |
Output is correct |
17 |
Correct |
1 ms |
7000 KB |
Output is correct |
18 |
Correct |
1 ms |
7256 KB |
Output is correct |
19 |
Correct |
1 ms |
7256 KB |
Output is correct |
20 |
Correct |
2 ms |
7000 KB |
Output is correct |
21 |
Incorrect |
1 ms |
6960 KB |
1st lines differ - on the 1st token, expected: '759476520', found: '833967706' |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
7000 KB |
Output is correct |
2 |
Correct |
1 ms |
7000 KB |
Output is correct |
3 |
Correct |
1 ms |
7000 KB |
Output is correct |
4 |
Correct |
1 ms |
7000 KB |
Output is correct |
5 |
Correct |
1 ms |
7000 KB |
Output is correct |
6 |
Correct |
1 ms |
7000 KB |
Output is correct |
7 |
Correct |
1 ms |
7000 KB |
Output is correct |
8 |
Correct |
1 ms |
7000 KB |
Output is correct |
9 |
Correct |
1 ms |
7000 KB |
Output is correct |
10 |
Correct |
1 ms |
7000 KB |
Output is correct |
11 |
Correct |
2 ms |
7000 KB |
Output is correct |
12 |
Correct |
1 ms |
7000 KB |
Output is correct |
13 |
Correct |
1 ms |
7000 KB |
Output is correct |
14 |
Correct |
1 ms |
7000 KB |
Output is correct |
15 |
Correct |
1 ms |
7000 KB |
Output is correct |
16 |
Correct |
1 ms |
7000 KB |
Output is correct |
17 |
Correct |
1 ms |
7000 KB |
Output is correct |
18 |
Correct |
1 ms |
7256 KB |
Output is correct |
19 |
Correct |
1 ms |
7256 KB |
Output is correct |
20 |
Correct |
2 ms |
7000 KB |
Output is correct |
21 |
Incorrect |
1 ms |
6960 KB |
1st lines differ - on the 1st token, expected: '759476520', found: '833967706' |
22 |
Halted |
0 ms |
0 KB |
- |