Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
long long贡献了3次wrong Answer#include<string.h> #include<cstdio> using namespace std; int n,i,j,k,a[500001],c[500001]; long long sum; void qsort(int l,int r) { if(l==r)return; int mid=(l+r)/2; qsort(l,mid); qsort(mid+1,r); int i=l,j=mid+1,m=l-1; while(i<=mid&&j<=r) { m++; if(a[i]<=a[j]) { c[m]=a[i]; i++; continue; } c[m]=a[j]; j++; sum+=mid-i+1; } while(i<=mid) { m++; c[m]=a[i]; i++; } while(j<=r) { m++; c[m]=a[j]; j++; } for(i=l;i<=r;++i)a[i]=c[i]; } int main() { scanf("%d",&n); while(n!=0) { for(i=1;i<=n;++i)scanf("%d",&a[i]); sum=0; qsort(1,n); printf("%lld\n",sum); scanf("%d",&n); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator