Luogu 1966 Match Queuing discretization + reverse order

Source: Internet
Author: User

Test instructions: Find the smallest change logarithm to make the I large and b array of the A array equal to the first I

Then A, B, array numbering is sorted, then the array shows the number of numbers in the first

One more key step: c[a[i].id]=b[i].id

is essentially a new array, according to the existing array of a arrangement, and b array to compare, to see if there is a reverse of the existence, there is a need to replace, so the reverse order can be

#include <bits/stdc++.h>#defineRep (i,x,y) for (register int i=x;i<=y;i++)#defineDec (i,x,y) for (register int i=x;i>=y;i--)#defineLL Long Long#defineint long Longusing namespacestd;Const intMod=99999997;Const intn=2e6+ -; inlineintRead () {intx=0, f=1;CharCh=GetChar ();  while(!isdigit (CH)) {if(ch=='-') f=-1; ch=GetChar ();}  while(IsDigit (CH)) {x= (x<<1) + (x<<3) + (ch^ -); ch=GetChar ();} returnX*f;}intN,ans,c[n],k[n];p air<int,int>A[n],b[n];inlinevoidAddintXintD) { for(inti=x;i<=n;i+=i& (-i)) k[i]+=D;} InlineintQueryintx) {intans=0; for(inti=x;i;i-=i& (-i)) ans+=k[i];returnans;} Signed Main () {n=read (); Rep (I,1, n) a[i].first=read (), a[i].second=i; Rep (I,1, n) b[i].first=read (), b[i].second=i; Sort (a+1, A +1+n); sort (b +1, B +1+N); Rep (I,1, N) c[a[i].second]=B[i].second; Dec (i,n,1) ans= (Ans+query (c[i))%mod,add (C[i],1); printf ("%lld\n", Ans%mod);return 0;}

Luogu 1966 Match Queuing discretization + reverse order

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.