segment tree with min and max queries