Segment tree and other stuff