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
In order to use segtree class defined above, you will need to create a datatype(a struct most likely), which will implement the function merge(). It can also additionally implement split, if you need to define the split operation. | |
A sample is shown as "struct segtree_node" in the code above. | |
The segtree has to be instantiated with this defined data type. For example,as | |
segtree<segtree_node> s; | |
You have to first call the init function of the class, which will take | |
int n=number of elements in your array, | |
node[] = your inital array, | |
identity = an element such that merge(y,identity) = merge(identity,y) = y for all y's. |