提交记录 27334
提交时间 |
评测时间 |
2024-11-13 02:38:39 |
2024-11-13 02:38:45 |
#include <array>
void sort(unsigned* a, int n) {
constexpr int BASE_WIDTH = 8;
constexpr unsigned BASE = 1 << BASE_WIDTH;
auto cursors = std::array<std::array<int, BASE>, 4>();
for (int i = 0; i < n; i++) {
cursors[0][a[i] & (BASE - 1)]++;
cursors[1][(a[i] >> BASE_WIDTH) & (BASE - 1)]++;
cursors[2][(a[i] >> (2 * BASE_WIDTH)) & (BASE - 1)]++;
cursors[3][a[i] >> (3 * BASE_WIDTH)]++;
}
for (int iter = 0; iter < 4; iter++) {
int prefix_offset = 0;
for (unsigned v = 0; v < BASE; v++) {
std::swap(prefix_offset, cursors[iter][v]);
prefix_offset += cursors[iter][v];
}
}
auto buffer = new unsigned[n];
for (int i = 0; i < n; i++) {
buffer[cursors[0][a[i] & (BASE - 1)]++] = a[i];
}
for (int i = 0; i < n; i++) {
a[cursors[1][(buffer[i] >> BASE_WIDTH) & (BASE - 1)]++] = buffer[i];
}
for (int i = 0; i < n; i++) {
buffer[cursors[2][(a[i] >> (2 * BASE_WIDTH)) & (BASE - 1)]++] = a[i];
}
for (int i = 0; i < n; i++) {
a[cursors[3][buffer[i] >> (3 * BASE_WIDTH)]++] = buffer[i];
}
delete[] buffer;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 1.011 ms | 804 KB | Accepted | Score: 34 | 显示更多 |
Testcase #2 | 1.08 s | 762 MB + 988 KB | Accepted | Score: 33 | 显示更多 |
Testcase #3 | 2.162 s | 1525 MB + 924 KB | Accepted | Score: 33 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2024-11-22 05:48:34 | Loaded in 0 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠