#include<bits/stdc++.h>
using namespace std;
unsigned b[100000001];
void sort(unsigned *a, int n) {
int cnt[256];
memset(cnt,0,sizeof(cnt));
for(int i=n-1; i>=0; --i) a[i+1]=a[i];
//memcpy(a+1,a,n*4+4);
register unsigned i, pw = 0;
for (i = 1; i <= n - 3; i += 4)
++cnt[(a[i] >> pw) & 255], ++cnt[(a[i + 1] >> pw) & 255], ++cnt[(a[i + 2] >> pw) & 255], ++cnt[(a[i + 3] >> pw) & 255];
while (i <= n)
++cnt[(a[i++] >> pw) & 255];
for (i = 1; i < 256 - 3; i += 4)
cnt[i + 3] += cnt[i + 2] += cnt[i + 1] += cnt[i] += cnt[i - 1];
while (i < 256)
cnt[i] += cnt[i - 1], ++i;
for (i = n; i >= 1 + 3; i -= 4)
b[cnt[(a[i] >> pw) & 255]--] = a[i], b[cnt[(a[i - 1] >> pw) & 255]--] = a[i - 1],
b[cnt[(a[i - 2] >> pw) & 255]--] = a[i - 2], b[cnt[(a[i - 3] >> pw) & 255]--] = a[i - 3];
while (i >= 1)
b[cnt[(a[i] >> pw) & 255]--] = a[i], --i;
pw += 8;
memset(cnt, 0, sizeof(cnt));
for (i = 1; i <= n - 3; i += 4)
++cnt[(b[i] >> pw) & 255], ++cnt[(b[i + 1] >> pw) & 255], ++cnt[(b[i + 2] >> pw) & 255], ++cnt[(b[i + 3] >> pw) & 255];
while (i <= n)
++cnt[(b[i++] >> pw) & 255];
for (i = 1; i < 256 - 3; i += 4)
cnt[i + 3] += cnt[i + 2] += cnt[i + 1] += cnt[i] += cnt[i - 1];
while (i < 256)
cnt[i] += cnt[i - 1], ++i;
for (i = n; i >= 1 + 3; i -= 4)
a[cnt[(b[i] >> pw) & 255]--] = b[i], a[cnt[(b[i - 1] >> pw) & 255]--] = b[i - 1],
a[cnt[(b[i - 2] >> pw) & 255]--] = b[i - 2], a[cnt[(b[i - 3] >> pw) & 255]--] = b[i - 3];
while (i >= 1)
a[cnt[(b[i] >> pw) & 255]--] = b[i], --i;
pw += 8;
memset(cnt, 0, sizeof(cnt));
for (i = 1; i <= n - 3; i += 4)
++cnt[(a[i] >> pw) & 255], ++cnt[(a[i + 1] >> pw) & 255], ++cnt[(a[i + 2] >> pw) & 255], ++cnt[(a[i + 3] >> pw) & 255];
while (i <= n)
++cnt[(a[i++] >> pw) & 255];
for (i = 1; i < 256 - 3; i += 4)
cnt[i + 3] += cnt[i + 2] += cnt[i + 1] += cnt[i] += cnt[i - 1];
while (i < 256)
cnt[i] += cnt[i - 1], ++i;
for (i = n; i >= 1 + 3; i -= 4)
b[cnt[(a[i] >> pw) & 255]--] = a[i], b[cnt[(a[i - 1] >> pw) & 255]--] = a[i - 1],
b[cnt[(a[i - 2] >> pw) & 255]--] = a[i - 2], b[cnt[(a[i - 3] >> pw) & 255]--] = a[i - 3];
while (i >= 1)
b[cnt[(a[i] >> pw) & 255]--] = a[i], --i;
pw += 8;
memset(cnt, 0, sizeof(cnt));
for (i = 1; i <= n - 3; i += 4)
++cnt[(b[i] >> pw) & 255], ++cnt[(b[i + 1] >> pw) & 255], ++cnt[(b[i + 2] >> pw) & 255], ++cnt[(b[i + 3] >> pw) & 255];
while (i <= n)
++cnt[(b[i++] >> pw) & 255];
for (i = 1; i < 256 - 3; i += 4)
cnt[i + 3] += cnt[i + 2] += cnt[i + 1] += cnt[i] += cnt[i - 1];
while (i < 256)
cnt[i] += cnt[i - 1], ++i;
for (i = n; i >= 1 + 3; i -= 4)
a[cnt[(b[i] >> pw) & 255]--] = b[i], a[cnt[(b[i - 1] >> pw) & 255]--] = b[i - 1],
a[cnt[(b[i - 2] >> pw) & 255]--] = b[i - 2], a[cnt[(b[i - 3] >> pw) & 255]--] = b[i - 3];
while (i >= 1)
a[cnt[(b[i] >> pw) & 255]--] = b[i], --i;
for(int i=0; i<n; ++i) a[i]=a[i+1];
//memcpy(a,a+1,n*4+4);
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Testcase #1 | 913.763 ms | 762 MB + 996 KB | Accepted | Score: 100 | 显示更多 |