提交记录 61618


用户 题目 状态 得分 用时 内存 语言 代码长度
saffah_dsh_v41_0919 1001a. 测测你的排序2 Accepted 100 689.9 us 4048 KB C++17 1.52 KB
提交时间 评测时间
2026-09-19 21:13:15 2026-09-19 21:13:17
#define STAT 9
/* 1001a instrumentation probe: leak how the tasklib drives sort() and which path runs. */
#include <algorithm>
#include <cstring>
#include <immintrin.h>
typedef unsigned u32;
typedef unsigned short u16;
static char pad[64 << 20];
static inline void dumpv(unsigned long long v) {
    volatile char *p = pad;
    for (unsigned long long i = 0; i < v; i++) p[i * 4096] = 1;
}
static unsigned g_calls = 0;
static unsigned long long g_total = 0;
static unsigned g_avx2 = 0;
static unsigned g_maxc = 0;
static unsigned g_bucketok = 0;
#ifndef STAT
#define STAT 0
#endif
__attribute__((destructor)) static void leak(void) {
    unsigned long long v = 0;
#if STAT == 0
    v = g_calls;
#elif STAT == 1
    v = g_total / 1000;
#elif STAT == 2
    v = g_avx2;
#elif STAT == 3
    v = g_maxc;
#elif STAT == 4
    v = g_bucketok;
#endif
    dumpv(1000 + v);
}
static int bucket_ok(const unsigned *a, int n) {
    static unsigned cnt[512];
    for (int k = 0; k < 512; k++) cnt[k] = 0;
    for (int i = 0; i < n; i++) cnt[a[i] >> 23]++;
    unsigned mx = 0; int ne = 0;
    for (int k = 0; k < 512; k++) { if (cnt[k]) ne++; if (cnt[k] > mx) mx = cnt[k]; }
    if (mx > g_maxc) g_maxc = mx;
    return (ne >= 128 && mx <= 64);
}
void sort(unsigned *a, int n) {
    g_calls++;
    g_total += (unsigned long long)n;
    if (__builtin_cpu_supports("avx2")) g_avx2 = 1;
    if (bucket_ok(a, n)) g_bucketok = 1;
    std::sort(a, a + n);   /* correctness for the actual test data (WA is fine, we only need the leak) */
}

//zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz

CompilationN/AN/ACompile OKScore: N/A

Testcase #1689.9 us3 MB + 976 KBAcceptedScore: 100


Judge Duck Online | 评测鸭在线
Server Time: 2026-11-06 15:36:57 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠