@@ -144,7 +144,22 @@ impl<F: MapMonoid> LazySegtree<F> {
144144 self . update ( p >> i) ;
145145 }
146146 }
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+
148163 assert ! ( l <= r && r <= self . n) ;
149164 if l == r {
150165 return ;
@@ -386,9 +401,13 @@ mod tests {
386401 internal[ 6 ] = 0 ;
387402 check_segtree ( & internal, & mut segtree) ;
388403
389- segtree. apply_range ( 3 , 8 , 2 ) ;
404+ segtree. apply_range ( 3 .. 8 , 2 ) ;
390405 internal[ 3 ..8 ] . iter_mut ( ) . for_each ( |e| * e += 2 ) ;
391406 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) ;
392411 }
393412
394413 //noinspection DuplicatedCode
0 commit comments