Skip to content

Commit d27354e

Browse files
authored
Update Contents.swift
1 parent a9fa8db commit d27354e

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Segment Tree/LazyPropagation/LazyPropagation.playground/Contents.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class LazySegmentTree {
4141
return
4242
}
4343

44-
let middle = leftBound + (rightBound - leftBound) / 2
44+
let middle = (leftBound + rightBound) / 2
4545
leftChild = LazySegmentTree(array: array, leftBound: leftBound, rightBound: middle)
4646
rightChild = LazySegmentTree(array: array, leftBound: middle + 1, rightBound: rightBound)
4747
if let leftChild = leftChild, let rightChild = rightChild {
@@ -62,8 +62,8 @@ public class LazySegmentTree {
6262

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

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
6767

6868
if leftBound <= middle { result += leftChild.query(leftBound: leftBound, rightBound: rightBound) }
6969
if rightBound > middle { result += rightChild.query(leftBound: leftBound, rightBound: rightBound) }
@@ -80,7 +80,7 @@ public class LazySegmentTree {
8080
guard let leftChild = leftChild else { fatalError("leftChild should not be nil") }
8181
guard let rightChild = rightChild else { fatalError("rightChild should not be nil") }
8282

83-
let middle = self.rightBound + (self.leftBound - self.rightBound) / 2
83+
let middle = (self.leftBound + self.rightBound) / 2
8484

8585
if index <= middle { leftChild.update(index: index, incremental: incremental) }
8686
else { rightChild.update(index: index, incremental: incremental) }
@@ -95,12 +95,12 @@ public class LazySegmentTree {
9595
return
9696
}
9797

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") }
100100

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

103-
let middle = self.rightBound + (self.leftBound - self.rightBound) / 2
103+
let middle = (self.leftBound + self.rightBound) / 2
104104

105105
if leftBound <= middle { leftChild.update(leftBound: leftBound, rightBound: rightBound, incremental: incremental) }
106106
if middle < rightBound { rightChild.update(leftBound: leftBound, rightBound: rightBound, incremental: incremental) }

0 commit comments

Comments
 (0)