Title: http://codevs.cn/problem/3286/
3286 Match Line
2013 Noip National League Improvement Group
time limit: 1 sspace limit: 128000 KBtitle level: Diamonds Diamond SolvingTitle Description
Description
Han Han has two boxes of matches, each containing n matches, each match has a height. Now the matches in each box are lined up in one column, the same match height is different, and the distance between the two matches is defined as:
, where AI represents the height of the first match in a match, and BI represents the height of the I match in the second row of matches.
The positions of the two adjacent matches in each match can be exchanged, so that the distance between the two matches is minimized by swapping. How many times do I have to exchange the minimum distance? If this number is too large, output the result of this minimum interchange number to 99,999,997 modulo.
Enter a description
Input Description
A total of three rows, the first line contains an integer n, indicating the number of matches in each box.
The second line has n integers, separated by a space between each two integers, representing the height of the first row of matches.
The third line has n integers, separated by a space between each two integers, indicating the height of the second row of matches.
Output description
Output Description
Outputs a common line that contains an integer that represents the result of a minimum number of interchanges for 99,999,997 modulo.
Sample input
Sample Input
[Sample 1]
4
2 3 1 4
3 2 1 4
[Sample 2]
4
1 3 4 2
1 7 2 4
Sample output
Sample Output
[Sample 1]
1
[Sample 2]
2
Data range and Tips
Data Size & Hint
"Sample 1 description"
The minimum distance is 0, which needs to be exchanged at least 1 times, such as exchanging the first 2 matches of the 1th column or exchanging the first 2 matches of the 2nd column.
"Sample 2 description"
The minimum distance is 10, the minimum need to exchange 2 times, such as: Swap the position of the Middle 2 matches in the 1th column, and then swap the position of the 2 matches in the 2nd column.
"Data Range"
For 10% of data, 1≤n≤10;
For 30% of data, 1≤n≤100;
For 60% of data, 1≤n≤1,000;
For 100% of data, 1≤n≤100,000,0≤ matches are highly ≤2^31-1.
Exercises
Tree Array + reverse order
and bzoj2789 almost the same, more simple than that ...
After sorting, direct the number of reverse order ...
The year of zero burst ... Smg...
1#include <bits/stdc++.h>2 using namespacestd;3 #defineMOD 999999974 #defineLL Long Long5 #defineMAXN 1000106 structnode7 {8 intv,w;9 }A[MAXN],B[MAXN];Ten intBit[maxn],c[maxn],n; One intRead () A { - ints=0, fh=1;CharCh=GetChar (); - while(ch<'0'|| Ch>'9'){if(ch=='-') fh=1; ch=GetChar ();} the while(ch>='0'&&ch<='9') {s=s*Ten+ (ch-'0'); ch=GetChar ();} - returns*fh; - } - BOOLCMP (node Aa,node BB) + { - returnaa.v<BB.V; + } A intLowbit (intO) {returno& (-o);} at voidUpdate (intOintO1) - { - while(o<=N) - { -bit[o]+=O1; -o+=lowbit (o); in } - } toLL Sum (into) + { -LL sum=0; the while(o>0) * { $sum+=(LL) bit[o];Panax Notoginsengo-=lowbit (o); - } the returnsum; + } A intMain () the { + inti; - LL ans; $n=read (); $ for(i=1; i<=n;i++) A[i].v=read (), a[i].w=i; - for(i=1; i<=n;i++) B[i].v=read (), b[i].w=i; -Sort (A +1, a+n+1, CMP); theSort (b +1, b+n+1, CMP); - for(i=1; i<=n;i++) c[a[i].w]=B[I].W;Wuyimemset (BIT,0,sizeof(BIT)); theans=0; - for(i=n;i>=1; i--) Wu { -Ans= (ans+ (LL) Sum (c[i]-1))%MOD; AboutUpdate (C[i],1); $ } -printf"%lld", ans); - fclose (stdin); - fclose (stdout); A return 0; +}
Codevs 3286 matches queued 2013 Noip National League increase Group Tree array, reverse