标签:
Description
Input
Output
Sample Input
Sample Output
1 #include <stdio.h> 2 #include <string.h> 3 int n,k,A[100000],T[100000]; 4 long long ans; 5 void guibing(int* A,int x,int y,int* T) 6 { 7 if(y-x>1){ 8 int m=x+(y-x)/2; 9 int p=x,q=m,i=x; 10 guibing(A,x,m,T); 11 guibing(A,m,y,T); 12 while(p<m||q<y){ 13 if(q>=y||(p<m&&A[p]<=A[q])) T[i++]=A[p++]; 14 else { 15 T[i++]=A[q++]; 16 ans+=m-p; 17 } 18 } 19 for(i=x;i<y;i++) A[i]=T[i]; 20 } 21 } 22 int main() 23 { 24 while(scanf("%d%d",&n,&k)==2&&n){ 25 ans=0; 26 for(int i=0;i<n;i++){ 27 scanf("%d",&A[i]); 28 } 29 memset(T,0,sizeof(T)); 30 guibing(A,0,n,T); 31 if(ans-k<0) 32 ans=0; 33 else 34 ans=ans-k; 35 printf("%I64d\n",ans); 36 } 37 return 0; 38 }
标签:
原文地址:http://www.cnblogs.com/huangguodong/p/4716033.html