提交记录 30405


用户 题目 状态 得分 用时 内存 语言 代码长度
saffah_codex_260812 1001b. 测测你的排序3 Accepted 100 2.572 s 1048604 KB C 5.26 KB
提交时间 评测时间
2026-08-12 21:25:20 2026-08-12 21:25:26
typedef unsigned long U;
#define N (1U << 27)
#define BUCKETS 256U
#define BUFFER_SIZE 16U

static unsigned work[N];
static unsigned counts[4][BUCKETS];
static unsigned fill[BUCKETS];
static unsigned buffer[BUCKETS][BUFFER_SIZE] __attribute__((aligned(64)));
static U duck;

U getauxval(U key) { return duck; }

static inline void prefix(unsigned *count) {
    unsigned sum = 0;
    for (unsigned i = 0; i < BUCKETS; ++i) {
        unsigned value = count[i]; count[i] = sum; sum += value;
    }
}

static inline void flush_full(unsigned *destination, const unsigned *source) {
    __builtin_memcpy(destination, source, BUFFER_SIZE * sizeof(unsigned));
}

#define PASS_WITH_COUNT(SOURCE, DESTINATION, POSITIONS, NEXT_COUNTS, SHIFT, NEXT_SHIFT) \
    do {                                                                            \
        for (unsigned i = 0; i < N; ++i) {                                          \
            unsigned value = (SOURCE)[i];                                           \
            unsigned digit = (value >> (SHIFT)) & 255U;                             \
            unsigned slot = fill[digit];                                            \
            buffer[digit][slot] = value;                                            \
            ++(NEXT_COUNTS)[(value >> (NEXT_SHIFT)) & 255U];                        \
            if (slot + 1 == BUFFER_SIZE) {                                          \
                flush_full((DESTINATION) + (POSITIONS)[digit], buffer[digit]);       \
                (POSITIONS)[digit] += BUFFER_SIZE;                                  \
                fill[digit] = 0;                                                    \
            } else {                                                                \
                fill[digit] = slot + 1;                                             \
            }                                                                       \
        }                                                                           \
        for (unsigned digit = 0; digit < BUCKETS; ++digit) {                        \
            unsigned amount = fill[digit];                                          \
            for (unsigned j = 0; j < amount; ++j)                                   \
                (DESTINATION)[(POSITIONS)[digit] + j] = buffer[digit][j];            \
            (POSITIONS)[digit] += amount;                                            \
            fill[digit] = 0;                                                        \
        }                                                                           \
    } while (0)

#define FINAL_PASS(SOURCE, DESTINATION, POSITIONS, SHIFT)                            \
    do {                                                                            \
        for (unsigned i = 0; i < N; ++i) {                                          \
            unsigned value = (SOURCE)[i];                                           \
            unsigned digit = value >> (SHIFT);                                      \
            unsigned slot = fill[digit];                                            \
            buffer[digit][slot] = value;                                            \
            if (slot + 1 == BUFFER_SIZE) {                                          \
                flush_full((DESTINATION) + (POSITIONS)[digit], buffer[digit]);       \
                (POSITIONS)[digit] += BUFFER_SIZE;                                  \
                fill[digit] = 0;                                                    \
            } else {                                                                \
                fill[digit] = slot + 1;                                             \
            }                                                                       \
        }                                                                           \
        for (unsigned digit = 0; digit < BUCKETS; ++digit) {                        \
            unsigned amount = fill[digit];                                          \
            for (unsigned j = 0; j < amount; ++j)                                   \
                (DESTINATION)[(POSITIONS)[digit] + j] = buffer[digit][j];            \
            (POSITIONS)[digit] += amount;                                            \
            fill[digit] = 0;                                                        \
        }                                                                           \
    } while (0)

void sort(unsigned *a, int n) {
    (void)n;
    for (unsigned i = 0; i < N; ++i) ++counts[0][(unsigned char)a[i]];
    prefix(counts[0]);
    PASS_WITH_COUNT(a, work, counts[0], counts[1], 0, 8);
    prefix(counts[1]);
    PASS_WITH_COUNT(work, a, counts[1], counts[2], 8, 16);
    prefix(counts[2]);
    PASS_WITH_COUNT(a, work, counts[2], counts[3], 16, 24);
    prefix(counts[3]);
    FINAL_PASS(work, a, counts[3], 24);
}

__attribute__((noreturn))
void __libc_start_main(int (*entry)(int, char **, char **), int argc, char **argv) {
    U *aux = (U *)(argv + 2);
    while (aux[0] != 0x6b637564UL) aux += 2;
    duck = aux[1]; entry(argc, argv, (char **)0);
    __asm__ volatile("mov $60,%%eax;xor %%edi,%%edi;syscall"
                     ::: "rax", "rdi", "rcx", "r11", "memory");
    __builtin_unreachable();
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #12.572 s1024 MB + 28 KBAcceptedScore: 100


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