Skip to content

Commit c2ca86a

Browse files
authored
Update CompactSegmentTree.java
1 parent 5442b56 commit c2ca86a

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

com/williamfiset/datastructures/segmenttree/CompactSegmentTree.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
package com.williamfiset.datastructures.segmenttree;
77

88
public class CompactSegmentTree {
9-
109
private int N;
1110

1211
// Let UNIQUE be a value which does NOT
@@ -32,15 +31,13 @@ public CompactSegmentTree(long[] values) {
3231
// Common associative functions used with segment trees
3332
// include: min, max, sum, product, GCD, and etc...
3433
private long function(long a, long b) {
35-
3634
if (a == UNIQUE) return b;
3735
else if (b == UNIQUE) return a;
3836

3937
// return a + b; // sum over a range
4038
// return (a > b) ? a : b; // maximum value over a range
4139
return (a < b) ? a : b; // minimum value over a range
4240
// return a * b; // product over a range (watch out for overflow!)
43-
4441
}
4542

4643
// Adjust point i by a value, O(log(n))
@@ -58,7 +55,9 @@ public long query(int l, int r) {
5855
if ((l&1) != 0) res = function(res, tree[l++]);
5956
if ((r&1) != 0) res = function(res, tree[--r]);
6057
}
58+
if (res == UNIQUE) {
59+
throw new IllegalStateException("UNIQUE should not be the return value.");
60+
}
6161
return res;
6262
}
63-
6463
}

0 commit comments

Comments
 (0)