segment tree + binary search