Skip to content

Commit 7e02142

Browse files
committed
updates
1 parent 2daca5f commit 7e02142

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

library/data_structures_[l,r)/seg_tree_uncommon/kd_tree.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22
using T = int64_t;
3-
const T unit = 0;
4-
T op(T a, T b) { return a + b; }
3+
const T unit = LLONG_MIN;
4+
T op(T a, T b) { return max(a, b); }
55
template<int K> struct KD_SEG {
66
int n;
77
vector<KD_SEG<K - 1>> s;
@@ -10,7 +10,7 @@ template<int K> struct KD_SEG {
1010
void update(int p, auto... a) {
1111
p += n;
1212
s[p].update(a...);
13-
for (p /= 2; p > 0; p /= 2)
13+
for (; p /= 2;)
1414
s[p].pull(s[2 * p], s[2 * p + 1], a...);
1515
}
1616
T query(int l, int r, auto... a) {
@@ -25,7 +25,7 @@ template<int K> struct KD_SEG {
2525
int p, auto... a) {
2626
p += n;
2727
s[p].pull(left.s[p], right.s[p], a...);
28-
for (p /= 2; p > 0; p /= 2)
28+
for (; p /= 2;)
2929
s[p].pull(s[2 * p], s[2 * p + 1], a...);
3030
}
3131
};

tests/library_checker_aizu_tests/data_structures/kd_bit_and_tree.test.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ int main() {
1313
for (int j = 0; j < m; j++) {
1414
int c;
1515
cin >> c;
16-
if (c) {
17-
bit.update(i, j, 1);
18-
tree.update(i, j, 1);
19-
}
16+
tree.update(i, j, c);
17+
if (c) bit.update(i, j, 1);
2018
}
2119
}
2220
int res = 0;
@@ -25,10 +23,10 @@ int main() {
2523
int start = 0, end = min(n - i, m - j) + 1;
2624
while (start + 1 < end) {
2725
int mid = (start + end) / 2;
28-
int sum = bit.query(i, i + mid, j, j + mid);
29-
assert(sum == tree.query(i, i + mid, j, j + mid));
30-
if (sum == 0)
31-
start = mid;
26+
int sum = bit.query(i, i + mid, j, j + mid);
27+
assert(
28+
(sum > 0) == tree.query(i, i + mid, j, j + mid));
29+
if (sum == 0) start = mid;
3230
else end = mid;
3331
}
3432
res = max(res, start);

0 commit comments

Comments
 (0)