#K68657. Count Reverse Pairs
Count Reverse Pairs
Count Reverse Pairs
You are given an array of n integers. A reverse pair is defined as a pair of indices \( (i, j) \) such that \( 0 \le i < j 2 \times \text{nums}[j] \). Your task is to compute the total number of reverse pairs in the array.
Example: For the array [1, 3, 2, 3, 1], there are 2 reverse pairs: (3, 4) and (1, 4) (using 0-indexing).
Note: All comparisons must use the exact condition \( \text{nums}[i] > 2 \times \text{nums}[j] \), where the multiplication is explicit.
inputFormat
The first line of input contains an integer n
representing the number of elements in the array. The second line contains n
space-separated integers representing the elements of the array.
outputFormat
Output a single integer that denotes the number of reverse pairs in the array.
## sample5
1 3 2 3 1
2