solution for line segment based on PriorityQueue and BinarySearchTree