Inverse pairs + discrete tree array + ....

Source: Internet
Author: User

There are three kinds of methods for reverse order: 1, Discrete tree array, 2, line tree, 3, merge sort

Today did the next rokua of P1908 reverse order to;

1, the beginning of a tree-like array, has been re, and later in the discovery of their own has been neglected discretization.

#include <iostream>#include<algorithm>using namespacestd;Const intMAXN =400000+5; typedefLong LongLl;ll N,HASH[MAXN],BT[MAXN];structNode {intV,id;} A[maxn];ll Lowbit (ll x) {return(x) & (-x);}voidAdd (ll i,ll b) { while(i<=N) {Bt[i]+=b; I+=lowbit (i); }}ll Qu (ll i) {ll ans=0;  while(i>0) {ans+=Bt[i]; I-=lowbit (i); }    returnans;}BOOLCMP (node A,node b) {returna.v<B.V;}intMain () {CIN>>N;  for(intI=1; i<=n; i++) {cin>>a[i].v; A[i].id=i; } sort (A+1, A +1+n,cmp);  for(intI=1; i<=n;i++) {Hash[a[i].id]=i; }    //The end of discretization;ll sum =0;  for(intI=1; i<=n;i++) {sum+ = (-1-qu (Hash[i]));//the number of i-1, Quary (A[i]) prefixes and a[i] before the current tree arrayAdd (Hash[i],1);//a value of a[i] adds another} cout<<sum<<Endl; return 0;}

Inverse pairs + discrete tree array + ....

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.