提交记录 21427


用户 题目 状态 得分 用时 内存 语言 代码长度
webmaster 1001c. 测测你的排序4 Accepted 100 3.795 s 1048608 KB C++17 872 B
提交时间 评测时间
2024-03-20 17:57:27 2024-03-20 17:57:36
#include <iostream>

#define ceil_div(u, v) (((u) - 1) / (v) + 1)

using namespace std;

static const uint32_t BASE = 6;
static const uint32_t CHUNK_NUM = ceil_div(32, BASE);
static const uint32_t CHUNK_SIZE = 1u << BASE;
static const uint32_t CHUNK_MASK = CHUNK_SIZE - 1;

void sort(unsigned *a, int n) {
    uint32_t cnt[CHUNK_NUM][CHUNK_SIZE] = {};
    for (int i = 0; i < n; ++i)
        for (uint32_t j = 0, k = a[i]; j < CHUNK_NUM; ++j, k >>= BASE)
            ++cnt[j][k & CHUNK_MASK];

    uint32_t *s = new uint32_t[n];
    uint32_t *t = s;
    for (uint32_t i = 0; i < CHUNK_NUM; ++i) {
        for (uint32_t j = 1; j < CHUNK_SIZE; ++j)
            cnt[i][j] += cnt[i][j - 1];
        for (int j = 1; j <= n; ++j) {
            int k = n - j;
            t[--cnt[i][(a[k] >> (BASE * i)) & CHUNK_MASK]] = a[k];
        }
        swap(a, t);
    }
    delete[]s;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #13.795 s1024 MB + 32 KBAcceptedScore: 100


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