@@ -13,14 +13,14 @@ import (
13
13
14
14
const emptyLazyNode = 0
15
15
16
- //SegmentTree with original Array and the Segment Tree Array
16
+ // SegmentTree with original Array and the Segment Tree Array
17
17
type SegmentTree struct {
18
18
Array []int
19
19
SegmentTree []int
20
20
LazyTree []int
21
21
}
22
22
23
- //Propagate lazy tree node values
23
+ // Propagate lazy tree node values
24
24
func (s * SegmentTree ) Propagate (node int , leftNode int , rightNode int ) {
25
25
if s .LazyTree [node ] != emptyLazyNode {
26
26
//add lazy node value multiplied by (right-left+1), which represents all interval
@@ -42,8 +42,8 @@ func (s *SegmentTree) Propagate(node int, leftNode int, rightNode int) {
42
42
}
43
43
}
44
44
45
- //Query on interval [firstIndex, leftIndex]
46
- //node, leftNode and rightNode always should start with 1, 0 and len(Array)-1
45
+ // Query on interval [firstIndex, leftIndex]
46
+ // node, leftNode and rightNode always should start with 1, 0 and len(Array)-1
47
47
func (s * SegmentTree ) Query (node int , leftNode int , rightNode int , firstIndex int , lastIndex int ) int {
48
48
if (firstIndex > lastIndex ) || (leftNode > rightNode ) {
49
49
//outside the interval
@@ -67,10 +67,10 @@ func (s *SegmentTree) Query(node int, leftNode int, rightNode int, firstIndex in
67
67
return leftNodeSum + rightNodeSum
68
68
}
69
69
70
- //Update Segment Tree
71
- //node, leftNode and rightNode always should start with 1, 0 and len(Array)-1
72
- //index is the Array index that you want to update
73
- //value is the value that you want to override
70
+ // Update Segment Tree
71
+ // node, leftNode and rightNode always should start with 1, 0 and len(Array)-1
72
+ // index is the Array index that you want to update
73
+ // value is the value that you want to override
74
74
func (s * SegmentTree ) Update (node int , leftNode int , rightNode int , firstIndex int , lastIndex int , value int ) {
75
75
//propagate lazy tree
76
76
s .Propagate (node , leftNode , rightNode )
@@ -96,8 +96,8 @@ func (s *SegmentTree) Update(node int, leftNode int, rightNode int, firstIndex i
96
96
}
97
97
}
98
98
99
- //Build Segment Tree
100
- //node, leftNode and rightNode always should start with 1, 0 and len(Array)-1
99
+ // Build Segment Tree
100
+ // node, leftNode and rightNode always should start with 1, 0 and len(Array)-1
101
101
func (s * SegmentTree ) Build (node int , left int , right int ) {
102
102
if left == right {
103
103
//leaf node
0 commit comments