1from sortedcontainers import SortedList234class Solution:5"""6For each sub array nums[0, i]7We sum the reverse pairs count8of x, s.t x in [0, i-1] and nums[x] >= 2 * nums[i] + 19Using a BST(sortedList) to get logN insert and lookup time.10Time: O(NlogN)11Space: O(N)12"""1314def reversePairs(self, nums: List[int]) -> int:15res = 016bst = SortedList()17for e in nums:18res += len(bst) - bst.bisect_left(2 * e + 1) # the count is the N - index19bst.add(e) # add the the bst20return res