nyoj-the number of reverse----------------to be solved, WA

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.