@@ -144,7 +144,22 @@ impl<F: MapMonoid> LazySegtree<F> {
144
144
self . update ( p >> i) ;
145
145
}
146
146
}
147
- pub fn apply_range ( & mut self , mut l : usize , mut r : usize , f : F :: F ) {
147
+ pub fn apply_range < R > ( & mut self , range : R , f : F :: F )
148
+ where
149
+ R : RangeBounds < usize > ,
150
+ {
151
+ let mut r = match range. end_bound ( ) {
152
+ Bound :: Included ( r) => r + 1 ,
153
+ Bound :: Excluded ( r) => * r,
154
+ Bound :: Unbounded => self . n ,
155
+ } ;
156
+ let mut l = match range. start_bound ( ) {
157
+ Bound :: Included ( l) => * l,
158
+ Bound :: Excluded ( l) => l + 1 ,
159
+ // TODO: There are another way of optimizing [0..r)
160
+ Bound :: Unbounded => 0 ,
161
+ } ;
162
+
148
163
assert ! ( l <= r && r <= self . n) ;
149
164
if l == r {
150
165
return ;
@@ -386,9 +401,13 @@ mod tests {
386
401
internal[ 6 ] = 0 ;
387
402
check_segtree ( & internal, & mut segtree) ;
388
403
389
- segtree. apply_range ( 3 , 8 , 2 ) ;
404
+ segtree. apply_range ( 3 .. 8 , 2 ) ;
390
405
internal[ 3 ..8 ] . iter_mut ( ) . for_each ( |e| * e += 2 ) ;
391
406
check_segtree ( & internal, & mut segtree) ;
407
+
408
+ segtree. apply_range ( 2 ..=5 , 7 ) ;
409
+ internal[ 2 ..=5 ] . iter_mut ( ) . for_each ( |e| * e += 7 ) ;
410
+ check_segtree ( & internal, & mut segtree) ;
392
411
}
393
412
394
413
//noinspection DuplicatedCode
0 commit comments