Skip to content

Commit 50ee8fa

Browse files
authored
Merge pull request #107 from rainbou-kpr/seg-assert
add assert to segtree
2 parents 546214e + 6d83a31 commit 50ee8fa

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

.verify-helper/timestamps.remote.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
"test/aoj-cgl-3-c.test.cpp": "2023-09-07 23:01:33 +0900",
99
"test/aoj-cgl-4-a.test.cpp": "2023-09-07 23:01:33 +0900",
1010
"test/aoj-cgl-5-a.test.cpp": "2023-09-07 23:01:33 +0900",
11-
"test/aoj-dsl-2-a.test.cpp": "2024-03-06 15:05:55 +0900",
11+
"test/aoj-dsl-2-a.test.cpp": "2024-03-11 22:28:50 +0900",
1212
"test/aoj-dsl-2-a.test.py": "2023-09-07 14:26:13 +0900",
13-
"test/aoj-dsl-2-b.test.cpp": "2024-03-06 15:05:55 +0900",
13+
"test/aoj-dsl-2-b.test.cpp": "2024-03-11 22:28:50 +0900",
1414
"test/aoj-dsl-2-b.test.py": "2023-09-07 14:26:13 +0900",
1515
"test/aoj-dsl-2-f.test.cpp": "2023-08-01 17:59:54 +0900",
1616
"test/aoj-dsl-2-g.test.cpp": "2023-08-01 17:59:54 +0900",
@@ -20,13 +20,13 @@
2020
"test/aoj-grl-5-b.test.cpp": "2023-06-16 15:41:49 +0900",
2121
"test/atcoder-abc177-f.1.test.cpp": "2023-08-01 17:59:54 +0900",
2222
"test/atcoder-abc177-f.2.test.cpp": "2023-08-01 17:59:54 +0900",
23-
"test/atcoder-abc185-f.test.cpp": "2024-03-06 15:05:55 +0900",
24-
"test/atcoder-abc254-f.test.cpp": "2024-03-06 15:05:55 +0900",
23+
"test/atcoder-abc185-f.test.cpp": "2024-03-11 22:28:50 +0900",
24+
"test/atcoder-abc254-f.test.cpp": "2024-03-11 22:28:50 +0900",
2525
"test/atcoder-abc282-d.test.cpp": "2023-11-30 23:29:28 +0900",
2626
"test/atcoder-abc300-b.test.cpp": "2023-10-12 08:50:40 +0900",
27-
"test/atcoder-abc331-f.test.cpp": "2024-03-06 18:33:07 +0900",
27+
"test/atcoder-abc331-f.test.cpp": "2024-03-11 22:28:50 +0900",
2828
"test/atcoder-edpc-g.test.cpp": "2023-11-30 23:29:28 +0900",
29-
"test/atcoder-past202012-n.test.cpp": "2024-03-06 15:05:55 +0900",
29+
"test/atcoder-past202012-n.test.cpp": "2024-03-11 22:28:50 +0900",
3030
"test/atcoder-past202012-n.test.py": "2023-09-07 14:26:13 +0900",
3131
"test/yosupo-binomial-coefficient.test.cpp": "2023-09-16 00:25:06 +0900",
3232
"test/yosupo-convolution-mod-1000000007.test.cpp": "2023-09-16 00:07:15 +0900",
@@ -38,14 +38,14 @@
3838
"test/yosupo-exp-of-fps.test.cpp": "2024-01-20 00:58:37 +0900",
3939
"test/yosupo-inv-of-fps.test.cpp": "2024-01-20 00:58:37 +0900",
4040
"test/yosupo-lca.1.test.cpp": "2023-06-16 15:41:49 +0900",
41-
"test/yosupo-lca.2.test.cpp": "2024-03-06 15:05:55 +0900",
41+
"test/yosupo-lca.2.test.cpp": "2024-03-11 22:28:50 +0900",
4242
"test/yosupo-line-add-get-min.test.cpp": "2023-06-19 07:11:52 +0900",
4343
"test/yosupo-log-of-fps.test.cpp": "2024-01-20 00:58:37 +0900",
4444
"test/yosupo-partition-function_1.test.cpp": "2024-01-20 00:58:37 +0900",
4545
"test/yosupo-partition-function_2.test.cpp": "2024-01-20 00:58:37 +0900",
4646
"test/yosupo-point-add-rectangle-sum.test.cpp": "2023-06-25 14:14:02 +0900",
47-
"test/yosupo-point-set-range-composite.1.test.cpp": "2024-03-06 15:05:55 +0900",
48-
"test/yosupo-point-set-range-composite.2.test.cpp": "2024-03-06 15:05:55 +0900",
47+
"test/yosupo-point-set-range-composite.1.test.cpp": "2024-03-11 22:28:50 +0900",
48+
"test/yosupo-point-set-range-composite.2.test.cpp": "2024-03-11 22:28:50 +0900",
4949
"test/yosupo-point-set-range-composite.test.py": "2023-09-07 14:26:13 +0900",
5050
"test/yosupo-polynomial-taylor-shift.test.cpp": "2024-01-20 00:58:37 +0900",
5151
"test/yosupo-pow-of-fps.test.cpp": "2024-01-20 00:58:37 +0900",

cpp/segtree.hpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ class SegTreeBase {
6464
* @param k インデックス
6565
* @return S 値
6666
*/
67-
S get(int k) const { return data[sz + k]; }
67+
S get(int k) const {
68+
assert(0 <= k && k < n);
69+
return data[sz + k];
70+
}
6871
/**
6972
* @brief 指定された要素の値を返す
7073
*
@@ -105,6 +108,7 @@ class SegTreeBase {
105108
* @param x 新しい値
106109
*/
107110
void set(int k, const S& x) {
111+
assert(0 <= k && k < n);
108112
k += sz;
109113
data[k] = x;
110114
for (int i = 1; i <= height; i++) update(k >> i);
@@ -121,10 +125,11 @@ class SegTreeBase {
121125
* @brief [l, r)の区間の総積を返す
122126
*
123127
* @param l 半開区間の開始
124-
* @param r 半開区間の終端
128+
* @param r 半開区間の終端 0<=l<=r<=n
125129
* @return S 総積
126130
*/
127131
S prod(int l, int r) const {
132+
assert(0 <= l && l <= r && r <= n);
128133
S left_prod = e(), right_prod = e();
129134
l += sz;
130135
r += sz;
@@ -148,13 +153,14 @@ class SegTreeBase {
148153
* fが単調なら、f(prod([l, r))) = trueとなる最大のr
149154
*
150155
* @tparam F
151-
* @param l 半開区間の開始
156+
* @param l 半開区間の開始 0<=l<=n
152157
* @param f 判定関数 f(e) = true
153158
* @return int
154159
*/
155160
template <typename F>
156161
int max_right(int l, F f) const {
157162
assert(f(e()));
163+
assert(0 <= l && l <= n);
158164
if (l == n) return n;
159165
l += sz;
160166
while (l % 2 == 0) l >>= 1;
@@ -179,13 +185,14 @@ class SegTreeBase {
179185
* fが単調なら、f(prod([l, r))) = trueとなる最小のl
180186
*
181187
* @tparam F
182-
* @param r 半開区間の終端
188+
* @param r 半開区間の終端 0<=r<=n
183189
* @param f 判定関数 f(e) = true
184190
* @return int
185191
*/
186192
template <typename F>
187193
int min_left(int r, F f) const {
188194
assert(f(e()));
195+
assert(0 <= r && r <= n);
189196
if (r == 0) return 0;
190197
r += sz;
191198
while (r % 2 == 0) r >>= 1;

0 commit comments

Comments
 (0)