@@ -41,7 +41,7 @@ public class LazySegmentTree {
41
41
return
42
42
}
43
43
44
- let middle = leftBound + ( rightBound - leftBound ) / 2
44
+ let middle = ( leftBound + rightBound) / 2
45
45
leftChild = LazySegmentTree ( array: array, leftBound: leftBound, rightBound: middle)
46
46
rightChild = LazySegmentTree ( array: array, leftBound: middle + 1 , rightBound: rightBound)
47
47
if let leftChild = leftChild, let rightChild = rightChild {
@@ -62,8 +62,8 @@ public class LazySegmentTree {
62
62
63
63
pushDown ( round: self . rightBound - self . leftBound + 1 , lson: leftChild, rson: rightChild)
64
64
65
- let middle = self . leftBound + ( self . rightBound - self . leftBound ) / 2
66
- var result : Int = 0
65
+ let middle = ( self . leftBound + self . rightBound) / 2
66
+ var result = 0
67
67
68
68
if leftBound <= middle { result += leftChild. query ( leftBound: leftBound, rightBound: rightBound) }
69
69
if rightBound > middle { result += rightChild. query ( leftBound: leftBound, rightBound: rightBound) }
@@ -80,7 +80,7 @@ public class LazySegmentTree {
80
80
guard let leftChild = leftChild else { fatalError ( " leftChild should not be nil " ) }
81
81
guard let rightChild = rightChild else { fatalError ( " rightChild should not be nil " ) }
82
82
83
- let middle = self . rightBound + ( self . leftBound - self . rightBound) / 2
83
+ let middle = ( self . leftBound + self . rightBound) / 2
84
84
85
85
if index <= middle { leftChild. update ( index: index, incremental: incremental) }
86
86
else { rightChild. update ( index: index, incremental: incremental) }
@@ -95,12 +95,12 @@ public class LazySegmentTree {
95
95
return
96
96
}
97
97
98
- guard let leftChild = leftChild else { fatalError ( ) }
99
- guard let rightChild = rightChild else { fatalError ( ) }
98
+ guard let leftChild = leftChild else { fatalError ( " leftChild should not be nil " ) }
99
+ guard let rightChild = rightChild else { fatalError ( " rightChild should not be nil " ) }
100
100
101
101
pushDown ( round: self . rightBound - self . leftBound + 1 , lson: leftChild, rson: rightChild)
102
102
103
- let middle = self . rightBound + ( self . leftBound - self . rightBound) / 2
103
+ let middle = ( self . leftBound + self . rightBound) / 2
104
104
105
105
if leftBound <= middle { leftChild. update ( leftBound: leftBound, rightBound: rightBound, incremental: incremental) }
106
106
if middle < rightBound { rightChild. update ( leftBound: leftBound, rightBound: rightBound, incremental: incremental) }
0 commit comments