Created
April 23, 2016 12:08
-
-
Save astiob/6bc1956a01f130b63f80ee6b7a6d62cb to your computer and use it in GitHub Desktop.
Dynamic [i, n] range maximum query
This file contains 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
T range_max(const T *binary_indexed_tree, size_t size, size_t first) | |
{ | |
T value = T_MIN; | |
for (; first < size; first |= first + 1) | |
if (value < binary_indexed_tree[first]) | |
value = binary_indexed_tree[first]; | |
return value; | |
} | |
void increase(T *binary_indexed_tree, size_t pos, T value) | |
{ | |
for (; pos != (size_t) -1; pos = (pos & pos + 1) - 1) | |
if (binary_indexed_tree[pos] < value) | |
binary_indexed_tree[pos] = value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment