#include<cstddef>
namespace ya
{
#define YA_RADIX_SORT_BASE 256
#define YA_RADIX_SORT_LOOP(Begin,End,Begin2,End2,OP) \
for(k=0;k!=YA_RADIX_SORT_BASE;++k)\
Cnt[k]=0;\
for(i=Begin;i!=End;++i)\
++Cnt[OP(*i)];\
i=Begin2;\
for(k=0;k!=YA_RADIX_SORT_BASE;++k)\
La[k]=(i+=Cnt[k]);\
i=End;\
do{\
--i;\
(*(--La[OP(*i)]))=(*i);\
}while(i!=Begin);
void radix_sort(unsigned int *Begin,unsigned int *End){
size_t N(End-Begin),Cnt[YA_RADIX_SORT_BASE],k;
unsigned int Begin2[N],*End2(Begin2+N),*La[YA_RADIX_SORT_BASE],*i;
#define YA_RADIX_SORT_UNSIGNED_INT_OP1(x) ((x)&255u)
#define YA_RADIX_SORT_UNSIGNED_INT_OP2(x) ((x)>>8&255u)
#define YA_RADIX_SORT_UNSIGNED_INT_OP3(x) ((x)>>16&255u)
#define YA_RADIX_SORT_UNSIGNED_INT_OP4(x) ((x)>>24)
YA_RADIX_SORT_LOOP(Begin,End,Begin2,End2,YA_RADIX_SORT_UNSIGNED_INT_OP1);
YA_RADIX_SORT_LOOP(Begin2,End2,Begin,End,YA_RADIX_SORT_UNSIGNED_INT_OP2);
YA_RADIX_SORT_LOOP(Begin,End,Begin2,End2,YA_RADIX_SORT_UNSIGNED_INT_OP3);
YA_RADIX_SORT_LOOP(Begin2,End2,Begin,End,YA_RADIX_SORT_UNSIGNED_INT_OP4);
}
};
void sort(unsigned *a, int n){
ya::radix_sort(a,a+n);
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 890.982 ms | 762 MB + 976 KB | Accepted | Score: 100 | 显示更多 |