1034740026
@_ llch_ 记得退登啊
namespace Radix_sort {
const int N = (1 << 20);
#define solve(a, b, end, base) {\
memset(buc, 0, sizeof(buc));\
for(T *it = a; it != end; it++) buc[((*it) >> base) & 255]++;\
std::partial_sum(buc, buc + 256, buc);\
for(T *it = end - 1, *be = a - 1; it != be; it--) b[--buc[((*it) >> base) & 255]] = (*it);\
}
template<typename T> void radix_sort(T *_begin, T *_end) {
assert(sizeof(int) * N >= sizeof(T) * (_end - _begin));
static int malloc[N];
T *buc = (T*)malloc, *alloc = (T*)malloc + 256;
T *a_end = alloc + (_end - _begin);
for(unsigned int base = 0; base < (sizeof(T) << 3); base += 16)
{ solve(_begin, alloc, _end, base); solve(alloc, _begin, a_end, base + 8); }
}
#undef solve
} using Radix_sort::radix_sort;