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

顶!

Posted by shenfangyi at 2006-11-09 12:09:13 on Problem 2299
In Reply To:why WA!!!help!! Posted by:shenfangyi at 2006-11-08 23:19:37
> #include<iostream>
> using namespace std;
> #define N 500000
> long long x,a[2][N];
> void merge(long long *sr,long long *tr,int i,int m,int n)
> {
> 	int j=m+1,k=i;
> 	for(;i<=m&&j<=n;++k)
> 	{
> 		if(sr[i]<=sr[j])tr[k]=sr[i++];
> 		else x+=j-k,tr[k]=sr[j++];
> 	}
> 	if(i<=m)for(;k<=n;)tr[k++]=sr[i++];
> 	if(j<=n)for(;k<=n;)tr[k++]=sr[j++];
> }
> int main()
> {
> 	int n;
> 	cin>>n;;
> 	while(n)
> 	{
> 		x=0;
> 		for(int i=0;i<n;i++)cin>>a[0][i];
> 		int k=0;
> 		for(int i=1;i<n;i*=2)
> 		{
> 			for(int j=0;j+i<n;j+=2*i)
> 			merge(a[k],a[(k+1)%2],j,j+i-1,(j+2*i-1)<(n-1)?(j+2*i-1):(n-1));
> 			k=(k+1)%2;
> 		}
> 		cout<<x<<endl;
> 		cin>>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