Set A to an ordered set of n numbers (n>1), where all the numbers are different. If there is a positive integer i, J makes 1≤i < j≤n and a[i] > A[j], then <a[i], a[j]> this ordered pair called a in reverse order.
the solution of inverse pairs first: bubbling (brute force)/enumeration directly bubbles the original sequence, counts the number of exchanges, and the number of exchanges = inverse logarithm. Note: The number of interchange of adjacent elements is equivalent to the inverse logarithm of the second sequence: the merge sort merges the original sequence, and the number of reverse pairs can be directly counted each time the two arrays are merged. For the element I in the left ordered sequence, and the element J in the right ordered sequence, if there is a[j] < A[i], then all elements after a[i] are greater than a[j]. In this case, the number of reverse pairs result = Mid-i + 1 The third: Discretization + Tree Array first uses discretization, reads all the data at once, then records the subscript and value of the reading data and sorts the values and subscripts by the size of the values. After the new data is obtained, a tree array with the new values (ordered ordinal numbers) is established, and the value of the tree array is the number of occurrences of that bit value in the current state. Each time you insert an element into a tree array, you use the tree array to query for the number of elements that are larger than the current value of the inserted element.
Three kinds of methods for reverse order