This is a segment tree implemented in Python