In the merge step, count the number of valid range sums that span across the two halves.
For each element in the left half, use binary search to find the range of indices in the right half that form valid range sums with the current element.
Add the count of these valid range sums to the total count.
Merge the two halves as in the standard merge sort algorithm.