-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSegmentTreeNode.java
More file actions
114 lines (103 loc) · 2.83 KB
/
SegmentTreeNode.java
File metadata and controls
114 lines (103 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
public class SegmentTreeNode extends TreeNode {
private int start;
private int end;
private int min;
private int max;
private int sum;
/**
* Constructs a new SegmentTreeNode with the given start and end indices.
*
* @param start The start index of the segment.
* @param end The end index of the segment.
*/
public SegmentTreeNode(int start, int end) {
super();
this.start = start;
this.end = end;
this.min = Integer.MAX_VALUE;
this.max = Integer.MIN_VALUE;
this.sum = 0;
}
/**
* Constructs a new SegmentTreeNode with the given start and end indices.
*
* @param start The start index of the segment.
* @param end The end index of the segment.
*/
public SegmentTreeNode(int start, int end, int min, int max, int sum,SegmentTreeNode left,SegmentTreeNode right) {
super(left,right);
this.start = start;
this.end = end;
this.min = min;
this.max = max;
this.sum = sum;
}
/**
* Returns the start index of the segment represented by this node.
*
* @return The start index of the segment.
*/
public int getStart() {
return start;
}
/**
* Returns the end index of the segment represented by this node.
*
* @return The end index of the segment.
*/
public int getEnd() {
return end;
}
/**
* Returns the minimum value of the segment represented by this node.
*
* @return The minimum value of the segment.
*/
public int getMin() {
return min;
}
/**
* Sets the minimum value of the segment represented by this node.
*
* @param min The minimum value of the segment.
*/
public void setMin(int min) {
this.min = min;
}
/**
* Returns the maximum value of the segment represented by this node.
*
* @return The maximum value of the segment.
*/
public int getMax() {
return max;
}
/**
* Sets the maximum value of the segment represented by this node.
*
* @param max The maximum value of the segment.
*/
public void setMax(int max) {
this.max = max;
}
/**
* Returns the sum of the segment represented by this node.
*
* @return The sum of the segment.
*/
public int getSum() {
return sum;
}
/**
* Sets the sum of the segment represented by this node.
*
* @param sum The sum of the segment.
*/
public void setSum(int sum) {
this.sum = sum;
}
@Override
public String toString() {
return "[" + start + "," + end + "] " + "min=" + min + " max=" + max + " sum=" + sum;
}
}