4040 }
4141}
4242
43- pub struct Sum < S > ( Infallible , PhantomData < fn ( ) -> S > ) ;
44- impl < S > Monoid for Sum < S >
43+ pub struct Additive < S > ( Infallible , PhantomData < fn ( ) -> S > ) ;
44+ impl < S > Monoid for Additive < S >
4545where
4646 S : Copy + Add < Output = S > + Zero ,
4747{
5454 }
5555}
5656
57- pub struct Product < S > ( Infallible , PhantomData < fn ( ) -> S > ) ;
58- impl < S > Monoid for Product < S >
57+ pub struct Multiplicative < S > ( Infallible , PhantomData < fn ( ) -> S > ) ;
58+ impl < S > Monoid for Multiplicative < S >
5959where
6060 S : Copy + Mul < Output = S > + One ,
6161{
@@ -136,10 +136,10 @@ impl<M: Monoid> Segtree<M> {
136136
137137 pub fn max_right < F > ( & self , mut l : usize , f : F ) -> usize
138138 where
139- F : Fn ( M :: S ) -> bool ,
139+ F : Fn ( & M :: S ) -> bool ,
140140 {
141141 assert ! ( l <= self . n) ;
142- assert ! ( f( M :: identity( ) ) ) ;
142+ assert ! ( f( & M :: identity( ) ) ) ;
143143 if l == self . n {
144144 return self . n ;
145145 }
@@ -150,11 +150,11 @@ impl<M: Monoid> Segtree<M> {
150150 while l % 2 == 0 {
151151 l >>= 1 ;
152152 }
153- if !f ( M :: binary_operation ( & sm, & self . d [ l] ) ) {
153+ if !f ( & M :: binary_operation ( & sm, & self . d [ l] ) ) {
154154 while l < self . size {
155155 l *= 2 ;
156156 let res = M :: binary_operation ( & sm, & self . d [ l] ) ;
157- if f ( res. clone ( ) ) {
157+ if f ( & res) {
158158 sm = res;
159159 l += 1 ;
160160 }
@@ -174,10 +174,10 @@ impl<M: Monoid> Segtree<M> {
174174
175175 pub fn min_left < F > ( & self , mut r : usize , f : F ) -> usize
176176 where
177- F : Fn ( M :: S ) -> bool ,
177+ F : Fn ( & M :: S ) -> bool ,
178178 {
179179 assert ! ( r <= self . n) ;
180- assert ! ( f( M :: identity( ) ) ) ;
180+ assert ! ( f( & M :: identity( ) ) ) ;
181181 if r == 0 {
182182 return 0 ;
183183 }
@@ -189,11 +189,11 @@ impl<M: Monoid> Segtree<M> {
189189 while r > 1 && r % 2 == 1 {
190190 r >>= 1 ;
191191 }
192- if !f ( M :: binary_operation ( & self . d [ r] , & sm) ) {
192+ if !f ( & M :: binary_operation ( & self . d [ r] , & sm) ) {
193193 while r < self . size {
194194 r = 2 * r + 1 ;
195195 let res = M :: binary_operation ( & self . d [ r] , & sm) ;
196- if f ( res. clone ( ) ) {
196+ if f ( & res) {
197197 sm = res;
198198 r -= 1 ;
199199 }
@@ -285,12 +285,12 @@ mod tests {
285285 base. iter( ) . max( ) . copied( ) . unwrap_or( i32 :: min_value( ) )
286286 ) ;
287287 for k in 0 ..=10 {
288- let f = |x | x < k;
288+ let f = |& x : & i32 | x < k;
289289 for i in 0 ..=n {
290290 assert_eq ! (
291291 Some ( segtree. max_right( i, f) ) ,
292292 ( i..=n)
293- . filter( |& j| f( base[ i..j]
293+ . filter( |& j| f( & base[ i..j]
294294 . iter( )
295295 . max( )
296296 . copied( )
@@ -302,7 +302,7 @@ mod tests {
302302 assert_eq ! (
303303 Some ( segtree. min_left( j, f) ) ,
304304 ( 0 ..=j)
305- . filter( |& i| f( base[ i..j]
305+ . filter( |& i| f( & base[ i..j]
306306 . iter( )
307307 . max( )
308308 . copied( )
0 commit comments