build segment tree