-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path203.h
More file actions
49 lines (45 loc) · 1.23 KB
/
203.h
File metadata and controls
49 lines (45 loc) · 1.23 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
/**
* Definition of SegmentTreeNode:
* class SegmentTreeNode {
* public:
* int start, end, max;
* SegmentTreeNode *left, *right;
* SegmentTreeNode(int start, int end, int max) {
* this->start = start;
* this->end = end;
* this->max = max;
* this->left = this->right = NULL;
* }
* }
*/
class Solution {
public:
/*
* @param root: The root of segment tree.
* @param index: index.
* @param value: value
* @return:
*/
void modify(SegmentTreeNode * root, int index, int value) {
// write your code here
query(root,index, value);
}
int query(SegmentTreeNode *root, int index, int val){
if(root == nullptr) return INT_MIN;
if(root->start == root->end){
if(root->start == index){
root->max = val;
return val;
}
else{
return root->max;
}
}
int start = root->start, end = root->end, l = INT_MIN, r = INT_MIN;
int mid = start + (end - start) / 2;
l = query(root->left, index, val);
r = query(root->right, index,val);
root->max = max(l, r);
return max(l, r);
}
};