40
40
}
41
41
}
42
42
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 >
45
45
where
46
46
S : Copy + Add < Output = S > + Zero ,
47
47
{
54
54
}
55
55
}
56
56
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 >
59
59
where
60
60
S : Copy + Mul < Output = S > + One ,
61
61
{
@@ -136,10 +136,10 @@ impl<M: Monoid> Segtree<M> {
136
136
137
137
pub fn max_right < F > ( & self , mut l : usize , f : F ) -> usize
138
138
where
139
- F : Fn ( M :: S ) -> bool ,
139
+ F : Fn ( & M :: S ) -> bool ,
140
140
{
141
141
assert ! ( l <= self . n) ;
142
- assert ! ( f( M :: identity( ) ) ) ;
142
+ assert ! ( f( & M :: identity( ) ) ) ;
143
143
if l == self . n {
144
144
return self . n ;
145
145
}
@@ -150,11 +150,11 @@ impl<M: Monoid> Segtree<M> {
150
150
while l % 2 == 0 {
151
151
l >>= 1 ;
152
152
}
153
- if !f ( M :: binary_operation ( & sm, & self . d [ l] ) ) {
153
+ if !f ( & M :: binary_operation ( & sm, & self . d [ l] ) ) {
154
154
while l < self . size {
155
155
l *= 2 ;
156
156
let res = M :: binary_operation ( & sm, & self . d [ l] ) ;
157
- if f ( res. clone ( ) ) {
157
+ if f ( & res) {
158
158
sm = res;
159
159
l += 1 ;
160
160
}
@@ -174,10 +174,10 @@ impl<M: Monoid> Segtree<M> {
174
174
175
175
pub fn min_left < F > ( & self , mut r : usize , f : F ) -> usize
176
176
where
177
- F : Fn ( M :: S ) -> bool ,
177
+ F : Fn ( & M :: S ) -> bool ,
178
178
{
179
179
assert ! ( r <= self . n) ;
180
- assert ! ( f( M :: identity( ) ) ) ;
180
+ assert ! ( f( & M :: identity( ) ) ) ;
181
181
if r == 0 {
182
182
return 0 ;
183
183
}
@@ -189,11 +189,11 @@ impl<M: Monoid> Segtree<M> {
189
189
while r > 1 && r % 2 == 1 {
190
190
r >>= 1 ;
191
191
}
192
- if !f ( M :: binary_operation ( & self . d [ r] , & sm) ) {
192
+ if !f ( & M :: binary_operation ( & self . d [ r] , & sm) ) {
193
193
while r < self . size {
194
194
r = 2 * r + 1 ;
195
195
let res = M :: binary_operation ( & self . d [ r] , & sm) ;
196
- if f ( res. clone ( ) ) {
196
+ if f ( & res) {
197
197
sm = res;
198
198
r -= 1 ;
199
199
}
@@ -285,12 +285,12 @@ mod tests {
285
285
base. iter( ) . max( ) . copied( ) . unwrap_or( i32 :: min_value( ) )
286
286
) ;
287
287
for k in 0 ..=10 {
288
- let f = |x | x < k;
288
+ let f = |& x : & i32 | x < k;
289
289
for i in 0 ..=n {
290
290
assert_eq ! (
291
291
Some ( segtree. max_right( i, f) ) ,
292
292
( i..=n)
293
- . filter( |& j| f( base[ i..j]
293
+ . filter( |& j| f( & base[ i..j]
294
294
. iter( )
295
295
. max( )
296
296
. copied( )
@@ -302,7 +302,7 @@ mod tests {
302
302
assert_eq ! (
303
303
Some ( segtree. min_left( j, f) ) ,
304
304
( 0 ..=j)
305
- . filter( |& i| f( base[ i..j]
305
+ . filter( |& i| f( & base[ i..j]
306
306
. iter( )
307
307
. max( )
308
308
. copied( )
0 commit comments