Segment tree miplementation in C++