Describe
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.
Now, to give you a sequence of n elements, you have to figure out how many reverse-order it is.
For example, 1 3 2 reverse number is 1.
-
-
Input
-
-
the first line enters an integer T that represents the number of groups of test data (1<=t<=5)
Each row of test data for each group is an integer n representing a total of n elements in the sequence (2〈=n〈=1000000)
The following line has a total of n integer Ai (0<=ai<1000000000), representing all the elements in the sequence.
Data assurance in multiple sets of test data, more than 100,000 numbers of test data have a maximum of one set.
-
-
Output
-
-
output the inverse number of the sequence
-
-
Sample input
-
-
221 131 3 2
-
-
Sample output
-
01
To be reasonable, the first reaction of this problem is to build an array and then traverse it and look at it. Zzzz looked at the data and canceled the idea.
But, brain remnants of a----do not have to set up an array, I just input data, the method of direct judgment, sure enough WA.
I said it couldn't be that simple.
zzzz Visual to use the knowledge of the data structure not learned, first horse, and so I finish the exam and then look.
1#include"iostream"2 using namespacestd;3 intMain () {4 intT;5Cin>>T;6 while(t--){7 intn,x,y,z;8Cin>>N;9 if(n>100000)Tent=0; Onex=0; Az=0; - for(intI=0; i<n;i++){ -Cin>>y; the if(y<x) -z++; -x=y; - } +cout<<z<<Endl; - } +}
nyoj-the number of reverse----------------to be solved, WA