turbo sort time limit exceeded error

#include <bits/stdc++.h>
#include
using namespace std;
void scanint(int &x)
{
char c = getchar_unlocked();//this will read the first character.
while(c<‘0’ || c>‘9’)
{
c = getchar_unlocked();//if the first character not between 0 & 9 this while loop will work
//untill it get the valid integer between 0 & 9
}

x=0;
while(c>=‘0’ && c<=‘9’)
{
x = 10 * x + c - 48;
c = getchar_unlocked();//rest of the characters goes here.
}
}

void quicksort(int x[],int first,int last)
{
int pivot,j,temp,i;

 if(first<last){
     pivot=first;
     i=first;
     j=last;

     while(i<j){
         while(x[i]<=x[pivot]&&i<last)
             i++;
         while(x[j]>x[pivot])
             j--;
         if(i<j){
             temp=x[i];
              x[i]=x[j];
              x[j]=temp;
         }
     }

     temp=x[pivot];
     x[pivot]=x[j];
     x[j]=temp;
     quicksort(x,first,j-1);
     quicksort(x,j+1,last);

}

}

int main() {

int t,arr[1000005];

scanint(t);

for(int i=0;i<t;i++)
{
 scanint(arr[i]);
}

quicksort(arr,0,t);

for(int i=0;i<t;i++)
printf(" %d\n",arr[i]);

return 0;

}

Try implementing Turbo Sort for this problem, as it is the a better sorting method for this problem rather than merge or quick sort.

You can find in detail about this approach in this thread:

http://discuss.codechef.com/questions/59947/tsort-swapping-of-2-numbers-using-bitwise-xor

Hey please do not use pivot always as first element. Please use randomized version of quick sort and you will get the correct answer. It will decrease your execution time and your answer will become correct.

Refer to my solutions using Quick sort and other methods:-

solutions