Title Description
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 . For example, a sequence of 4 5 1 3 2, then the number of reverse order of this sequence is 7, reverse pairs are (4, 1), (4, 3), (4, 2), (5, 1), (5, 3), (5, 2), (3, 2). Input Description:
The first line has an integer n (1 <= n <= 100000), then the second line follows n integers, for number I a[i], (0 <= a[i] <= 100000).
Output Description:
Output the number of reverse order in this sequence
Example 1input
54 5 1) 3 2
Output
7
Problem-solving ideas: There are several ways to find the number of reverse order, where the direct use of violent dafa (small data, violent dafa faster, but the usual practice or fast algorithm, at least to avoid timeouts)
AC Code:
1#include <bits/stdc++.h>2 using namespacestd;3 intMain ()4 {5 ints[100005]={0},n,a;6 Long Longsum=0;//avoid overflow with longlong storage7Cin>>N;8 while(n--){9Cin>>A;Tensum+=S[a]; One for(intI=0; i<a;i++) s[i]++;//Add the elements that are less than a A } -cout<<sum<<Endl; - return 0; the}
2018 National multi-school algorithm winter training Camp Practice Competition (fifth): a title: Reverse number