Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

long long贡献了3次wrong Answer

Posted by louchiheng at 2016-03-29 17:51:05 on Problem 2299
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator