1 reverse order number one wave:
In one arrangement, if the front and back positions of a pair of numbers are opposite to the size order, that is, the previous number is greater than the subsequent number, then they are called an inverse. The total number of reverse order in a permutation is called the inverse number of the permutation. The total number of reverse order in a permutation is called the reverse number of this arrangement. That is, for n different elements, the first rule between each element has a standard order (for example, n different natural numbers, can be specified from small to large for the standard order), so in any one of the n elements, when the order of a two elements and the standard order is not the same, said there are 1 reverse. The total number of reverse order in a permutation is called the reverse number of this arrangement.
For example: 2431 this arrangement,
21,31,41,43, these four are reverse, so the total number of reverse order is 4.
2. Tree-like array:
Https://www.cnblogs.com/zllwxm123/p/9342044.html
Refer to the above blog post.
3. Use a tree-like array to find the inverse number.
Set A[x] is a tree-like array, now we want to save is, X this number has appeared, appeared, a[x]++;
So when we sum up is the number of the current position before the figure is less than itself, then according to my own number of bits,
Can roll out more than my own number in front of me how many bits.
(Of course, if the numbers are large, you need to do discretization first.) )
For example:
Calculates the total number of inverse numbers for the following series of digits,
3425671
An array of a indicates whether I have appeared, and ANS indicates that before there are several numbers smaller than itself, the CNT array indicates that each number may be the number of the inverse number of the number that follows it, and that is the sum.
A[3] 1 ans[1] 0 cnt[1] = 3-ans[1]-1 = 2
A[4] 1 ans[2] 1 cnt[2] = 4-ans[2]-1 = 2
A[2] 1 ans[3] 0 cnt[3] = 2-ans[3]-1 = 1
A[5] 1 Ans[4] 3 cnt[4] = 5-ans[4]-1 = 1
A[6] 1 Ans[5] 4 cnt[5] = 6-ans[5]-1 = 1
A[7] 1 Ans[6] 5 cnt[6] = 7-ans[6]-1 = 1
A[1] 1 ans[7] 0 cnt[7] = 1-ans[7]-1 = 0
A tree-like array for reverse order number