Pagini recente » Cod sursa (job #2274410) | Cod sursa (job #2310200) | Cod sursa (job #262329) | Cod sursa (job #1456706) | Cod sursa (job #2450121)
#include <cstdio>
#include <algorithm>
using namespace std;
const int N=500007;
const int BLACK=1<<10;
int n;
int a[N];
int nw[N];
int len;
void NIGGA_SORT(int l,int r)
{
if(r-l+1<=BLACK)
{
sort(a+l,a+r+1);
return;
}
int m=(l+r)/2;
NIGGA_SORT(l,m);
NIGGA_SORT(m+1,r);
int pa=l,pb=m+1;
for(int j=l;j<=r;j++)
{
int tp=0;
if(pa>m)
tp=2;
if(pb>r)
tp=1;
if(tp==0)
if(a[pa]<a[pb])
tp=1;
else
tp=2;
if(tp==1)
nw[j]=a[pa++];
else
nw[j]=a[pb++];
}
for(int j=l;j<=r;j++)
a[j]=nw[j];
}
int main()
{
freopen("algsort.in","r",stdin),
freopen("algsort.out","w",stdout);
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
NIGGA_SORT(1,n);
for(int i=1;i<=n;i++)
printf("%d ",a[i]);
printf("\n");
return 0;
}