@@ -11,8 +11,8 @@ const INF = 2e9 // 2e15
11
11
class LiChaoTree {
12
12
private readonly _n : number
13
13
private readonly _offset : number
14
- private readonly _lower : number
15
- private readonly _higher : number
14
+ private readonly _start : number
15
+ private readonly _end : number
16
16
private readonly _compress : boolean
17
17
private readonly _minimize : boolean
18
18
private readonly _lineIds : Int32Array
@@ -33,11 +33,11 @@ class LiChaoTree {
33
33
34
34
/**
35
35
* 指定查询的 x 值范围建立李超线段树,不采用坐标压缩.
36
- * higher - lower <= 1e6.
36
+ * end - start <= 1e6.
37
37
*/
38
38
constructor (
39
- lower : number ,
40
- higher : number ,
39
+ start : number ,
40
+ end : number ,
41
41
options ?: {
42
42
minimize ?: boolean
43
43
evaluate ?: ( line : Line , x : number ) => number
@@ -56,8 +56,8 @@ class LiChaoTree {
56
56
const lineIds = new Int32Array ( offset << 1 ) . fill ( - 1 )
57
57
this . _n = n
58
58
this . _offset = offset
59
- this . _lower = 0
60
- this . _higher = 0
59
+ this . _start = 0
60
+ this . _end = 0
61
61
this . _compress = true
62
62
this . _minimize = minimize
63
63
this . _lineIds = lineIds
@@ -66,15 +66,16 @@ class LiChaoTree {
66
66
this . _evaluate = evaluate
67
67
} else {
68
68
const { minimize = true , evaluate = ( line : Line , x : number ) => line . k * x + line . b } = arg3 || { }
69
+ arg2 ++
69
70
const n = arg2 - arg1
70
71
let log = 1
71
72
while ( 1 << log < n ) log ++
72
73
const offset = 1 << log
73
74
const lineIds = new Int32Array ( offset << 1 ) . fill ( - 1 )
74
75
this . _n = n
75
76
this . _offset = offset
76
- this . _lower = arg1
77
- this . _higher = arg2
77
+ this . _start = arg1
78
+ this . _end = arg2
78
79
this . _compress = false
79
80
this . _minimize = minimize
80
81
this . _lineIds = lineIds
@@ -172,14 +173,14 @@ class LiChaoTree {
172
173
173
174
private _evaluateInner ( fid : number , x : number ) : number {
174
175
if ( fid === - 1 ) return this . _minimize ? INF : - INF
175
- const target = this . _compress ? this . _xs [ Math . min ( x , this . _n - 1 ) ] : x + this . _lower
176
+ const target = this . _compress ? this . _xs [ Math . min ( x , this . _n - 1 ) ] : x + this . _start
176
177
return this . _evaluate ( this . _lines [ fid ] , target )
177
178
}
178
179
179
180
private _getIndex ( x : number ) : number {
180
181
if ( this . _compress ) return LiChaoTree . _lowerBound ( this . _xs , x )
181
- if ( x < this . _lower || x > this . _higher ) throw new RangeError ( `x out of range: ${ x } ` )
182
- return x - this . _lower
182
+ if ( x < this . _start || x > this . _end ) throw new RangeError ( `x out of range: ${ x } ` )
183
+ return x - this . _start
183
184
}
184
185
185
186
private static _lowerBound ( arr : ArrayLike < number > , x : number ) : number {
@@ -239,7 +240,7 @@ if (require.main === module) {
239
240
const points = Array ( q )
240
241
. fill ( 0 )
241
242
. map ( ( ) => Math . floor ( - Math . random ( ) * 1e5 ) + 5e4 )
242
- const tree1 = new LiChaoTree ( points , { minimize : false } )
243
+ const tree1 = new LiChaoTree ( - 1e5 , 1e5 , { minimize : false } )
243
244
const tree2 = new Mocker ( false )
244
245
for ( let i = 0 ; i < q ; i ++ ) {
245
246
const k = - Math . floor ( Math . random ( ) * 1e5 ) + 5e4
0 commit comments