I did not check your code.But one thing i can say even if ur code avoid run time error, it can't avoid time limit exceed .Input size is 50000.So (n^2) bubble sort cant pass time limit, u have to use (nlogn) sorting algorithm like merge sort.
Best of luck with merge sort.
10810 - Ultra-QuickSort
Moderator: Board moderators
-
- Experienced poster
- Posts: 136
- Joined: Sat Nov 29, 2008 8:01 am
- Location: narayangong,bangladesh.
- Contact:
Re: 10810 - Ultra-QuickSort
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
Re: 10810 - Ultra-QuickSort
why i got WA in my code ?
please help me..
Code: Select all
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
static long long sw,n;
static long long v[500001];
void gabung(int p,int q,int r)
{
long long n1 = q-p+1;
long long n2 = r-q;
long long i,j;
long long L[n1+1], R[n2+1];
for (i=0;i<n1;i++)
L[i]=v[p+i];
for (j=0;j<n2;j++)
R[j]=v[q+j+1];
i=0;j=0;
L[n1]=1000000000;
R[n2]=1000000000;
for (int k=p;k<=r;k++)
{
if (L[i]<=R[j])
{
v[k]=L[i];
i++;
}
else
{
v[k]=R[j];
j++;
if (L[i]!=1000000000)
sw+=j;
}
}
}
void divide(int awal, int akhir)
{
if (awal < akhir)
{
long long q=(awal+akhir)/2;
divide(awal,q);
divide(q+1,akhir);
gabung(awal,q,akhir);
}
}
int main()
{
int temp;
while (cin>>n)
{
if (n==0)
break;
sw=0;
memset(v,0,sizeof(v));
for (int i=0;i<n;i++)
{
scanf("%lld",&v[i]);
}
divide(0,n-1);
cout<<sw<<endl;
//for (int i=0;i<n;i++)
// cout<<v[i]<<" ";
//cout<<endl;
}
return 0;
}
10810 - Ultra-QuickSort (Data type 'long' is enough)
I've used the Merge Sort approach and got Accepted with the long datatype. So, now a days I think long long is not necessary for this problem.
( <---- 24 November, 2010)
Also got Accepted in the BST approach... but it took greater runtime.
( <---- 24 November, 2010)
Also got Accepted in the BST approach... but it took greater runtime.
"I AM NOT SURE WHETHER I SHOULD BE CONFUSED OR NOT..."
TARIQ M NASIM
CSE 03/04 Batch, SUST, Sylhet- 3114.
==>Software Engineer, Structured Data Systems Limited,Dhaka.
Bangladesh.
e-Mail Address:
tariqmnasim@gmail.com
TARIQ M NASIM
CSE 03/04 Batch, SUST, Sylhet- 3114.
==>Software Engineer, Structured Data Systems Limited,Dhaka.
Bangladesh.
e-Mail Address:
tariqmnasim@gmail.com
-
- Experienced poster
- Posts: 147
- Joined: Mon Jun 07, 2010 11:43 am
- Location: University Of Dhaka,Bangladesh
- Contact:
Re: 10810 - Ultra-QuickSort
I got WA until i used LONG LONG.
Try this case:
ans 11
Try this case:
Code: Select all
10
324 123 123 123 213 435 678 234 879 234
0
UVa stats: http://felix-halim.net/uva/hunting.php?id=63448
My blog on programming: http://www.shafaetsplanet.com/planetcoding/
My blog on programming: http://www.shafaetsplanet.com/planetcoding/
Re: 10810 - Ultra-QuickSort
I tried using long too and accepted 
it mean the judge computer using 64bit now ?
i tried in the 64bit computer and print sizeof(long) and it return 8 which is sizeof(long long) in 32bit computer

it mean the judge computer using 64bit now ?
i tried in the 64bit computer and print sizeof(long) and it return 8 which is sizeof(long long) in 32bit computer
keep study every day
http://felix-halim.net/uva/hunting.php?id=99497
http://felix-halim.net/uva/hunting.php?id=99497
Re: 10810 - Ultra-QuickSort
Got accepted with mergesort 10810 (11858, 11495, 10327). This problem was useful to learn the way to find number of inversions in O(N*logN) with Divide and Conquer algorithm.

I think that straightforward solution with Quicksort will get TLE.gvcormac wrote:The sort in the problem is "quicksort" in name only.sohel wrote:I also used D&C and got AC in 2.14 seconds..
.. its funny that to solve a quicksort program, one has to implement merge sort.
- It also seems that some managed to solve it taking < 1sec time.
Is there any other method other then the classical merge sort?
There's a straightforward solution using quicksort. Just count the
number of inversions you have to do when you arrange the elements
about the pivot.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman