Skip to content

Commit 5e88407

Browse files
authored
Update README.markdown
1 parent d27354e commit 5e88407

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

Segment Tree/LazyPropagation/README.markdown

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public init(array: [Int], leftBound: Int, rightBound: Int) {
9797
return
9898
}
9999

100-
let middle = leftBound + (rightBound - leftBound) / 2
100+
let middle = (leftBound + rightBound) / 2
101101
leftChild = LazySegmentTree(array: array, leftBound: leftBound, rightBound: middle)
102102
rightChild = LazySegmentTree(array: array, leftBound: middle + 1, rightBound: rightBound)
103103
if let leftChild = leftChild, let rightChild = rightChild {
@@ -113,7 +113,7 @@ public func update(index: Int, incremental: Int) {
113113
guard let leftChild = leftChild else { fatalError("leftChild should not be nil") }
114114
guard let rightChild = rightChild else { fatalError("rightChild should not be nil") }
115115

116-
let middle = self.rightBound + (self.leftBound - self.rightBound) / 2
116+
let middle = (self.leftBound + self.rightBound) / 2
117117

118118
if index <= middle { leftChild.update(index: index, incremental: incremental) }
119119
else { rightChild.update(index: index, incremental: incremental) }
@@ -198,7 +198,7 @@ public class LazySegmentTree {
198198
return
199199
}
200200

201-
let middle = leftBound + (rightBound - leftBound) / 2
201+
let middle = (leftBound + rightBound) / 2
202202
leftChild = LazySegmentTree(array: array, leftBound: leftBound, rightBound: middle)
203203
rightChild = LazySegmentTree(array: array, leftBound: middle + 1, rightBound: rightBound)
204204
if let leftChild = leftChild, let rightChild = rightChild {
@@ -219,8 +219,8 @@ public class LazySegmentTree {
219219

220220
pushDown(round: self.rightBound - self.leftBound + 1, lson: leftChild, rson: rightChild)
221221

222-
let middle = self.leftBound + (self.rightBound - self.leftBound) / 2
223-
var result: Int = 0
222+
let middle = (self.leftBound + self.rightBound) / 2
223+
var result = 0
224224

225225
if leftBound <= middle { result += leftChild.query(leftBound: leftBound, rightBound: rightBound) }
226226
if rightBound > middle { result += rightChild.query(leftBound: leftBound, rightBound: rightBound) }
@@ -237,7 +237,7 @@ public class LazySegmentTree {
237237
guard let leftChild = leftChild else { fatalError("leftChild should not be nil") }
238238
guard let rightChild = rightChild else { fatalError("rightChild should not be nil") }
239239

240-
let middle = self.rightBound + (self.leftBound - self.rightBound) / 2
240+
let middle = (self.leftBound + self.rightBound) / 2
241241

242242
if index <= middle { leftChild.update(index: index, incremental: incremental) }
243243
else { rightChild.update(index: index, incremental: incremental) }
@@ -252,12 +252,12 @@ public class LazySegmentTree {
252252
return
253253
}
254254

255-
guard let leftChild = leftChild else { fatalError() }
256-
guard let rightChild = rightChild else { fatalError() }
255+
guard let leftChild = leftChild else { fatalError("leftChild should not be nil") }
256+
guard let rightChild = rightChild else { fatalError("rightChild should not be nil") }
257257

258258
pushDown(round: self.rightBound - self.leftBound + 1, lson: leftChild, rson: rightChild)
259259

260-
let middle = self.rightBound + (self.leftBound - self.rightBound) / 2
260+
let middle = (self.leftBound + self.rightBound) / 2
261261

262262
if leftBound <= middle { leftChild.update(leftBound: leftBound, rightBound: rightBound, incremental: incremental) }
263263
if middle < rightBound { rightChild.update(leftBound: leftBound, rightBound: rightBound, incremental: incremental) }
@@ -302,7 +302,3 @@ In fact, the operation of Segment Tree is far more than that. It can also be use
302302
---
303303

304304
*Written for Swift Algorithm Club by [Desgard_Duan](https://github.com/desgard)*
305-
306-
307-
308-

0 commit comments

Comments
 (0)