implement SegmentTree