build segment tree with query