Thanks for the explanations. Post my 239ms C++ version:

class Solution { public: int reversePairs(vector<int>& nums) { return mergeSort(nums, 0, nums.size()-1); } int mergeSort(vector<int>& nums, int l, int r) { if (l >= r) return 0; int mid = l + (r - l) / 2; int res = 0; res = mergeSort(nums, l, mid) + mergeSort(nums, mid+1, r); for (int i = mid+1; i <= r; i++) { auto it = upper_bound(nums.begin()+l, nums.begin()+mid+1, nums[i] * 2L); int dis = distance(nums.begin()+l, it); if (dis > mid-l) break; res += mid-l+1 - dis; } inplace_merge(nums.begin()+l, nums.begin()+mid+1, nums.begin()+r+1); return res; } };Reverse Pairs