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