4769: Super Chastity Fish
Time limit:1 Sec Memory limit:128 MB
Description Madagascar is a magical two-legged zhen fish, they write their own wisdom on the feet-each of the fish's left foot and the right foot on the last number. One day, K-only jade fish Mood cramps (1≤k≤10^5), row into a column, from left to right, the first 1≤ai≤10^9 will write Ai (in the right foot), the left foot on I (1≤i≤k), the second year, the K-only fish according to the number of the right foot from small to large row into a column, and then they decided to renumber, From left to right, I will write the number of the left foot on the right foot, write I on the left foot, and in the third year, they rearrange and renumber by the method of the second year. N years later (1≤N≤10^5), for the left to right of the first and second J, if i< J and the number of the right foot of the I-only-jeong fish is larger than the number on the right foot of the J-Jeong Fish, it is called a pair of "super-chaste fish". Ask the total number of "super-zhen Fish". Input is a total of 3 lines, the first line is a positive integer k (1≤k≤10^5), the second row K number from left to right input Ai (1≤ai≤10^9), the third row a positive integer n (1≤n≤10^5). Output an integer representing the logarithm of "super-chaste fish". Sample Input
65 2 6 3 1 70
Sample Output
7
HINT
For all data: ai≤10^9.
30% of Data:n,k<=400;
70% of Data:n,k<=10000;
100% of Data:n,k<=100000;
Proposition by Benny
Source
Roj Original
Merge sort naked question, we will find that when the reorder n is even, it is equivalent to the original sequence number (in fact, it is equivalent to a two-dollar structure, one by first sort, second by second), and then is equivalent to the number of reverse order of a series
It's better to disperse it first.
Attention!!! Data giant pits, n,k<=1,000,000 and AI have duplicate numbers!!
#include <map>#include<cmath>#include<queue>#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespacestd;#definell Long Long#defineN 1000100inlineintRead () {intx=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}intN,a[n],tmp[n],k;ll ji;voidGbintLintR) { if(L==R)return; intMid= (l+r) >>1, cnt=l,h1=l,h2=mid+1; GB (L,MID); GB (Mid+1, R); while(h1<=mid&&h2<=r) { while(a[h1]>A[H2]) {tmp[cnt++]=A[H2]; H2++; Ji+=mid-h1+1; if(H2>r) Break; } tmp[cnt++]=A[H1]; H1++; } for(inti=h1;i<=mid;i++) tmp[cnt++]=A[i]; for(inti=h2;i<=r;i++) tmp[cnt++]=A[i]; for(inti=l;i<=r;i++) a[i]=tmp[i];}structqaz{intX,p;} Tp[n];BOOLCMP (Qaz Q,qaz z) {if(q.x==z.x)returnq.p<z.p;returnq.x<z.x;}intMain () {n=read (); for(intI=1; i<=n;i++) {tp[i].x=read (); tp[i].p=i;} Sort (TP+1, tp+n+1, CMP); for(intI=1; i<=n;i++) a[tp[i].p]=i; K=read (); if(k&1) { for(intI=1; i<=n;i++) {tp[i].x=a[i];tp[i].p=i;} Sort (TP+1, tp+n+1, CMP); for(intI=1; i<=n;i++) a[i]=TP[I].P; } GB (1, N); printf ("%lld\n", Ji);}
Bzoj 4769: Super-zhen fish--merge sort