typedef unsigned u32;
u32 cnt1[1 << 8], cnt2[1 << 8], cnt3[1 << 8], cnt4[1 << 8];
void sort(unsigned *a, int n)
{
u32 *tmp = new u32[n];
u32 *end= a + n;
for (register u32 *i = a; i != a + n; i++)
++cnt1[*i & 0xff],
++cnt2[(*i >> 8) & 0xff],
++cnt3[(*i >> 16) & 0xff],
++cnt4[*i >> 24];
for(register u32 *i = cnt1 + 1, *j = cnt2 + 1, *k = cnt3 + 1, *l = cnt4 + 1; i <= cnt1 + 0xff; ++i, ++j, ++k, ++l)
*i += *(i - 1),
*j += *(j - 1),
*k += *(k - 1),
*l += *(l - 1);
for(register u32 *i= end - 1; i != a - 1; i-=8)
tmp[--cnt1[*i & 0xff]] = *i,
tmp[--cnt1[*(i - 1) & 0xff]] = *(i - 1),
tmp[--cnt1[*(i - 2) & 0xff]] = *(i - 2),
tmp[--cnt1[*(i - 3) & 0xff]] = *(i - 3),
tmp[--cnt1[*(i - 4) & 0xff]] = *(i - 4),
tmp[--cnt1[*(i - 5) & 0xff]] = *(i - 5),
tmp[--cnt1[*(i - 6) & 0xff]] = *(i - 6),
tmp[--cnt1[*(i - 7) & 0xff]] = *(i - 7);
for(register u32 *i= tmp + n - 1; i != tmp - 1; i-=8)
a[--cnt2[(*i >> 8) & 0xff]] = *i,
a[--cnt2[(*(i - 1) >> 8) & 0xff]] = *(i - 1),
a[--cnt2[(*(i - 2) >> 8) & 0xff]] = *(i - 2),
a[--cnt2[(*(i - 3) >> 8) & 0xff]] = *(i - 3),
a[--cnt2[(*(i - 4) >> 8) & 0xff]] = *(i - 4),
a[--cnt2[(*(i - 5) >> 8) & 0xff]] = *(i - 5),
a[--cnt2[(*(i - 6) >> 8) & 0xff]] = *(i - 6),
a[--cnt2[(*(i - 7) >> 8) & 0xff]] = *(i - 7);
for(register u32 *i= end - 1; i != a - 1; i-=8)
tmp[--cnt3[(*i >> 16) & 0xff]] = *i,
tmp[--cnt3[(*(i - 1) >> 16) & 0xff]] = *(i - 1),
tmp[--cnt3[(*(i - 2) >> 16) & 0xff]] = *(i - 2),
tmp[--cnt3[(*(i - 3) >> 16) & 0xff]] = *(i - 3),
tmp[--cnt3[(*(i - 4) >> 16) & 0xff]] = *(i - 4),
tmp[--cnt3[(*(i - 5) >> 16) & 0xff]] = *(i - 5),
tmp[--cnt3[(*(i - 6) >> 16) & 0xff]] = *(i - 6),
tmp[--cnt3[(*(i - 7) >> 16) & 0xff]] = *(i - 7);
for(register u32 *i= tmp + n - 1; i != tmp - 1; i-=8)
a[--cnt4[*i >> 24]] = *i,
a[--cnt4[*(i - 1) >> 24]] = *(i - 1),
a[--cnt4[*(i - 2) >> 24]] = *(i - 2),
a[--cnt4[*(i - 3) >> 24]] = *(i - 3),
a[--cnt4[*(i - 4) >> 24]] = *(i - 4),
a[--cnt4[*(i - 5) >> 24]] = *(i - 5),
a[--cnt4[*(i - 6) >> 24]] = *(i - 6),
a[--cnt4[*(i - 7) >> 24]] = *(i - 7);
delete[] tmp;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 1.016 ms | 804 KB | Accepted | Score: 34 | 显示更多 |
Testcase #2 | 1.109 s | 762 MB + 988 KB | Accepted | Score: 33 | 显示更多 |
Testcase #3 | 2.22 s | 1525 MB + 924 KB | Accepted | Score: 33 | 显示更多 |