This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // C++ program for range minimum | |
| // query using segment tree | |
| #include <bits/stdc++.h> | |
| using namespace std; | |
| // A utility function to get minimum of two numbers | |
| int minVal(int x, int y) { return (x < y)? x: y; } | |
| // A utility function to get the | |
| // middle index from corner indexes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <bits/stdc++.h> // using GCC/G++11 | |
| using namespace std; | |
| /** | |
| * Range Sum Query for Mutable Arrays using Segment Trees (LeetCode) | |
| * https://leetcode.com/problems/range-sum-query-mutable/ | |
| * | |
| * Build a tree whose nodes represent the entire range. Its two children represent the two halves | |
| * of this range. This continues down the tree with height log(n) until we reach the n individual | |
| * leaves of the tree (each representing a single element). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // C++ program to show segment tree operations like construction, query | |
| // and update | |
| #include <bits/stdc++.h> | |
| using namespace std; | |
| // A utility function to get the middle index from corner indexes. | |
| int getMid(int s, int e) { return s + (e -s)/2; } | |
| /* A recursive function to get the sum of values in the given range | |
| of the array. The following are parameters for this function. |