提交记录 29639
| 提交时间 |
评测时间 |
| 2026-08-07 20:58:45 |
2026-08-07 20:58:50 |
#include <algorithm>
void sort(unsigned *a, int n) {
if (n <= 1) return;
unsigned *tmp = new unsigned[n];
unsigned *src = a;
unsigned *dst = tmp;
// 对4个字节分别处理
for (int shift = 0; shift < 32; shift += 8) {
int count[256] = {0};
// 统计
for (int i = 0; i < n; i++) {
count[(src[i] >> shift) & 0xFF]++;
}
// 前缀和
int sum = 0;
for (int i = 0; i < 256; i++) {
int temp = count[i];
count[i] = sum;
sum += temp;
}
// 分发
for (int i = 0; i < n; i++) {
int idx = (src[i] >> shift) & 0xFF;
dst[count[idx]++] = src[i];
}
// 交换指针
unsigned *tempPtr = src;
src = dst;
dst = tempPtr;
}
// 如果最后数据在tmp中,复制回a
if (src != a) {
for (int i = 0; i < n; i++) {
a[i] = src[i];
}
}
delete[] tmp;
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Testcase #1 | 912.856 ms | 762 MB + 984 KB | Accepted | Score: 100 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2026-08-08 15:54:10 | Loaded in 0 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠