#include <iostream>
#include <vector>
using i64 = int64_t;
const i64 MOD = 1'000'002'022;
struct Node {
i64 a1, ax;
Node() : a1(0), ax(1) {}
explicit Node(bool value) : a1(value), ax(1) {}
Node(i64 a1, i64 ax) : a1(a1), ax(ax) {}
Node operator*(const Node &rhs) const {
return {(a1 * rhs.ax + ax * rhs.a1) % MOD, ax * rhs.ax * 2 % MOD};
}
};
struct SegmentTree {
std::vector<Node> values;
i64 offset;
SegmentTree() : values{}, offset{0} {}
explicit SegmentTree(size_t sz) : values(2 * sz), offset(sz) {}
void update(i64 idx, bool value) {
idx += offset;
values[idx] = Node(value);
while (idx /= 2) {
values[idx] = values[2 * idx] * values[2 * idx + 1];
}
}
const Node &root() const { return values[1]; }
};
int n, m;
std::vector<int> p, a;
SegmentTree st;
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
n = N;
m = M;
p = P;
a = A;
st = SegmentTree(N + 1);
for (i64 i = 0; i < M; i++) {
st.update(i, A[i]);
}
}
int count_ways(int l, int r) {
r += 1;
l -= n;
r -= n;
for (i64 i = l; i < r; i++) st.update(i, a[i] = !a[i]);
return st.root().a1;
}
Compilation message
circuit.cpp: In function 'int count_ways(int, int)':
circuit.cpp:64:51: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
64 | for (i64 i = l; i < r; i++) st.update(i, a[i] = !a[i]);
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Incorrect |
1 ms |
336 KB |
1st lines differ - on the 1st token, expected: '706880838', found: '573051996' |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
403 ms |
2384 KB |
Output is correct |
2 |
Correct |
737 ms |
4668 KB |
Output is correct |
3 |
Correct |
738 ms |
4644 KB |
Output is correct |
4 |
Correct |
674 ms |
4636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
403 ms |
2384 KB |
Output is correct |
2 |
Correct |
737 ms |
4668 KB |
Output is correct |
3 |
Correct |
738 ms |
4644 KB |
Output is correct |
4 |
Correct |
674 ms |
4636 KB |
Output is correct |
5 |
Execution timed out |
3071 ms |
2512 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Incorrect |
1 ms |
336 KB |
1st lines differ - on the 1st token, expected: '706880838', found: '573051996' |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |