Last active
November 5, 2020 16:29
-
-
Save sbsatter/d1f6d9fe528c9a9e23d22ea02119e1ba to your computer and use it in GitHub Desktop.
Segment tree for sum of elements in an array
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
int n; // size of array | |
int arr[n]; // global array of elements that are provided as input | |
int tree[4 * n]; // global structure for containing segment tree | |
// initialize with global array arr | |
build(1, 1, n); | |
// query | |
query(1, 1, n, a, b); // query against range [a, b] | |
// update | |
update(1, 1, n, idx, val); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment