@@ -9,14 +9,14 @@ pub trait MapMonoid {
9
9
Self :: M :: identity ( )
10
10
}
11
11
fn binary_operation (
12
- a : <Self :: M as Monoid >:: S ,
13
- b : <Self :: M as Monoid >:: S ,
12
+ a : & <Self :: M as Monoid >:: S ,
13
+ b : & <Self :: M as Monoid >:: S ,
14
14
) -> <Self :: M as Monoid >:: S {
15
15
Self :: M :: binary_operation ( a, b)
16
16
}
17
17
fn identity_map ( ) -> Self :: F ;
18
- fn mapping ( f : Self :: F , x : <Self :: M as Monoid >:: S ) -> <Self :: M as Monoid >:: S ;
19
- fn composition ( f : Self :: F , g : Self :: F ) -> Self :: F ;
18
+ fn mapping ( f : & Self :: F , x : & <Self :: M as Monoid >:: S ) -> <Self :: M as Monoid >:: S ;
19
+ fn composition ( f : & Self :: F , g : & Self :: F ) -> Self :: F ;
20
20
}
21
21
22
22
impl < F : MapMonoid > Default for LazySegtree < F > {
@@ -95,18 +95,18 @@ impl<F: MapMonoid> LazySegtree<F> {
95
95
let mut smr = F :: identity_element ( ) ;
96
96
while l < r {
97
97
if l & 1 != 0 {
98
- sml = F :: binary_operation ( sml, self . d [ l] . clone ( ) ) ;
98
+ sml = F :: binary_operation ( & sml, & self . d [ l] ) ;
99
99
l += 1 ;
100
100
}
101
101
if r & 1 != 0 {
102
102
r -= 1 ;
103
- smr = F :: binary_operation ( self . d [ r] . clone ( ) , smr) ;
103
+ smr = F :: binary_operation ( & self . d [ r] , & smr) ;
104
104
}
105
105
l >>= 1 ;
106
106
r >>= 1 ;
107
107
}
108
108
109
- F :: binary_operation ( sml, smr)
109
+ F :: binary_operation ( & sml, & smr)
110
110
}
111
111
112
112
pub fn all_prod ( & self ) -> <F :: M as Monoid >:: S {
@@ -119,7 +119,7 @@ impl<F: MapMonoid> LazySegtree<F> {
119
119
for i in ( 1 ..=self . log ) . rev ( ) {
120
120
self . push ( p >> i) ;
121
121
}
122
- self . d [ p] = F :: mapping ( f, self . d [ p] . clone ( ) ) ;
122
+ self . d [ p] = F :: mapping ( & f, & self . d [ p] ) ;
123
123
for i in 1 ..=self . log {
124
124
self . update ( p >> i) ;
125
125
}
@@ -190,19 +190,19 @@ impl<F: MapMonoid> LazySegtree<F> {
190
190
while l % 2 == 0 {
191
191
l >>= 1 ;
192
192
}
193
- if !g ( F :: binary_operation ( sm . clone ( ) , self . d [ l] . clone ( ) ) ) {
193
+ if !g ( F :: binary_operation ( & sm , & self . d [ l] ) ) {
194
194
while l < self . size {
195
195
self . push ( l) ;
196
196
l *= 2 ;
197
- let res = F :: binary_operation ( sm . clone ( ) , self . d [ l] . clone ( ) ) ;
197
+ let res = F :: binary_operation ( & sm , & self . d [ l] ) ;
198
198
if g ( res. clone ( ) ) {
199
199
sm = res;
200
200
l += 1 ;
201
201
}
202
202
}
203
203
return l - self . size ;
204
204
}
205
- sm = F :: binary_operation ( sm, self . d [ l] . clone ( ) ) ;
205
+ sm = F :: binary_operation ( & sm, & self . d [ l] ) ;
206
206
l += 1 ;
207
207
//while
208
208
{
@@ -233,19 +233,19 @@ impl<F: MapMonoid> LazySegtree<F> {
233
233
while r > 1 && r % 2 != 0 {
234
234
r >>= 1 ;
235
235
}
236
- if !g ( F :: binary_operation ( self . d [ r] . clone ( ) , sm . clone ( ) ) ) {
236
+ if !g ( F :: binary_operation ( & self . d [ r] , & sm ) ) {
237
237
while r < self . size {
238
238
self . push ( r) ;
239
239
r = 2 * r + 1 ;
240
- let res = F :: binary_operation ( self . d [ r] . clone ( ) , sm . clone ( ) ) ;
240
+ let res = F :: binary_operation ( & self . d [ r] , & sm ) ;
241
241
if g ( res. clone ( ) ) {
242
242
sm = res;
243
243
r -= 1 ;
244
244
}
245
245
}
246
246
return r + 1 - self . size ;
247
247
}
248
- sm = F :: binary_operation ( self . d [ r] . clone ( ) , sm) ;
248
+ sm = F :: binary_operation ( & self . d [ r] , & sm) ;
249
249
// while
250
250
{
251
251
let r = r as isize ;
@@ -271,12 +271,12 @@ where
271
271
F : MapMonoid ,
272
272
{
273
273
fn update ( & mut self , k : usize ) {
274
- self . d [ k] = F :: binary_operation ( self . d [ 2 * k] . clone ( ) , self . d [ 2 * k + 1 ] . clone ( ) ) ;
274
+ self . d [ k] = F :: binary_operation ( & self . d [ 2 * k] , & self . d [ 2 * k + 1 ] ) ;
275
275
}
276
276
fn all_apply ( & mut self , k : usize , f : F :: F ) {
277
- self . d [ k] = F :: mapping ( f . clone ( ) , self . d [ k] . clone ( ) ) ;
277
+ self . d [ k] = F :: mapping ( & f , & self . d [ k] ) ;
278
278
if k < self . size {
279
- self . lz [ k] = F :: composition ( f, self . lz [ k] . clone ( ) ) ;
279
+ self . lz [ k] = F :: composition ( & f, & self . lz [ k] ) ;
280
280
}
281
281
}
282
282
fn push ( & mut self , k : usize ) {
@@ -325,11 +325,11 @@ mod tests {
325
325
0
326
326
}
327
327
328
- fn mapping ( f : i32 , x : i32 ) -> i32 {
328
+ fn mapping ( & f: & i32 , & x: & i32 ) -> i32 {
329
329
f + x
330
330
}
331
331
332
- fn composition ( f : i32 , g : i32 ) -> i32 {
332
+ fn composition ( & f: & i32 , & g: & i32 ) -> i32 {
333
333
f + g
334
334
}
335
335
}
0 commit comments