implement simple segment tree