2018 National multi-school algorithm winter training Camp Practice Competition (fifth): a title: Reverse number

Source: Internet
Author: User

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

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.