HDU 1394 minimum inversion number in reverse order

Source: Internet
Author: User

The title of hangdian is also in reverse order. Its scale is much smaller than that of poj, so it does not need to be merged and direct brute force statistics are required.

This requires the smallest number of reverse orders. At the beginning, each sequence is re-computed using the merge statement. It is found that the time has timed out. Later, I checked the Report on other people's problem solving and found that the number of reverse orders that can be calculated from the beginning can be used. This question is special. The number of input N is 0 ~ N-1.

From this number hold [I] We can know that a Number smaller than it has hold [I], a number larger than it has a n-1-hold [I.

Every time hold [I] is put to the end, ANS = ANS-hold [I] + n-1-hold [I];

 

 # include 
  
    # include 
   
     # include 
    
      # define Max 500005 using namespace STD; long TMP [Max]; long hold [Max]; long long array [Max]; long ans; int num [Max]; int main () {int N; while (CIN> N) {for (INT I = 0; I 
     
       array [J]) num [I] ++; ans + = num [I];} long long _ min = ans; For (INT I = 0; I 
      
        ans) _ min = ans;} cout <_ min 
       
      
     
    
   
  

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.