提交记录 16069


用户 题目 状态 得分 用时 内存 语言 代码长度
ObsidianY 1001. 测测你的排序 Accepted 100 858.805 ms 805676 KB C++11 1.56 KB
提交时间 评测时间
2021-03-20 08:09:32 2021-03-20 08:09:37
#include <cstdint>
#include <cstring>

constexpr uint8_t kRadixBits = 8;
constexpr size_t kMaxN = 1e8, kRadix = 1 << kRadixBits;
constexpr uint32_t kRadixBitMask = kRadix - 1;
uint32_t buffer[kMaxN], cnt[kRadix] = {0};
uint8_t buf2[kMaxN/4];
#define DIGIT(X, shift_bits) (((X) >> (shift_bits)) & kRadixBitMask)
#define SORT(shift_bits)                                                  \
  {                                                                       \
    memset(cnt, 0, sizeof(cnt));                                          \
    for (uint32_t j = 0; j < n; ++j) ++cnt[DIGIT(buf_p0[j], shift_bits)]; \
    for (uint32_t j = 1; j < kRadix; ++j) cnt[j] += cnt[j - 1];           \
    for (int j = n - 1; j >= 0; --j)                                      \
      buf_p1[--cnt[DIGIT(buf_p0[j], shift_bits)]] = buf_p0[j];            \
    buf_pt = buf_p0, buf_p0 = buf_p1, buf_p1 = buf_pt;                    \
  }

void sort(unsigned* arr, int n) {
  uint32_t *buf_p0 = arr, *buf_p1 = buffer, *buf_pt;
  memset(buf2, 0, sizeof(buf2));
  // for (uint8_t shift_bits = 0; shift_bits < 32; shift_bits += kRadixBits) {
  //   memset(cnt, 0, sizeof(cnt));
  //   for (uint32_t j = 0; j < n; ++j) ++cnt[DIGIT(buf_p0[j], shift_bits)];
  //   for (uint32_t j = 1; j < kRadix; ++j) cnt[j] += cnt[j - 1];
  //   for (int j = n - 1; j >= 0; --j)
  //     buf_p1[--cnt[DIGIT(buf_p0[j], shift_bits)]] = buf_p0[j];
  //   buf_pt = buf_p0, buf_p0 = buf_p1, buf_p1 = buf_pt;
  // }
  SORT(0);
  SORT(8);
  SORT(16);
  SORT(24);
  if (buf_p0 != arr) memcpy(arr, buf_p0, n * sizeof(uint32_t));
  return;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #1858.805 ms786 MB + 812 KBAcceptedScore: 100


Judge Duck Online | 评测鸭在线
Server Time: 2024-11-24 00:18:08 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠