Skip to content

Commit 6956edb

Browse files
Merge pull request #4099 from SansPapyrus683/master
bugs me tbh
2 parents a51e11a + 529b15e commit 6956edb

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

content/4_Gold/PURS.mdx

+12-5
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ They will be covered in [platinum](/plat/seg-ext).
8787
```cpp
8888
#include <algorithm>
8989
#include <iostream>
90+
#include <limits>
9091
#include <vector>
9192

9293
using std::cout;
@@ -96,7 +97,7 @@ using std::vector;
9697
/** A data structure that can answer point update & range minimum queries. */
9798
template <class T> class MinSegmentTree {
9899
private:
99-
const T DEFAULT = 1e18; // Will overflow if T is an int
100+
const T DEFAULT = std::numeric_limits<T>().max();
100101

101102
vector<T> segtree;
102103
int len;
@@ -115,12 +116,12 @@ template <class T> class MinSegmentTree {
115116

116117
/** @return the minimum element in the range [start, end) */
117118
T range_min(int start, int end) {
118-
T sum = DEFAULT;
119+
T min = DEFAULT;
119120
for (start += len, end += len; start < end; start /= 2, end /= 2) {
120-
if (start % 2 == 1) { sum = std::min(sum, segtree[start++]); }
121-
if (end % 2 == 1) { sum = std::min(sum, segtree[--end]); }
121+
if (start % 2 == 1) { min = std::min(min, segtree[start++]); }
122+
if (end % 2 == 1) { min = std::min(min, segtree[--end]); }
122123
}
123-
return sum;
124+
return min;
124125
}
125126
};
126127

@@ -283,6 +284,7 @@ using std::cout;
283284
using std::endl;
284285
using std::vector;
285286

287+
// BeginCodeSnip{Segment Tree}
286288
template <class T> class SumSegmentTree {
287289
private:
288290
const T DEFAULT = 0;
@@ -310,6 +312,7 @@ template <class T> class SumSegmentTree {
310312
return sum;
311313
}
312314
};
315+
// EndCodeSnip
313316

314317
int main() {
315318
int arr_len;
@@ -406,6 +409,7 @@ Compared to the previous problem, all we need to change is the way we aggregate
406409
values (from `min()` to '+'), and change the initial value to 0.
407410
408411
```py
412+
# BeginCodeSnip{Segment Tree}
409413
class SumSegmentTree:
410414
def __init__(self, len_: int):
411415
self.len = len_
@@ -436,6 +440,9 @@ class SumSegmentTree:
436440
return total
437441

438442

443+
# EndCodeSnip
444+
445+
439446
arr_len, query_num = map(int, input().split())
440447
arr = list(map(int, input().split()))
441448

0 commit comments

Comments
 (0)