First attempt at the segment tree. WA, but passing test cases