Segment tree implementation in python