提交记录 34397


用户 题目 状态 得分 用时 内存 语言 代码长度
saffah_dsh_260814 1008. 测测你的二维数点 Accepted 100 1.607 s 312924 KB C++ 2.01 KB
提交时间 评测时间
2026-08-14 23:14:51 2026-08-14 23:15:00
// 2D dominance: 3-pass radix sort (x<<24|y) permuting index -> 2-level Fenwick (B=256).
#include <cstring>
typedef unsigned u32; typedef unsigned long long u64;

static u64 keys[10000000];
static u64 temp[10000000];
static u32 idx[10000000];
static u32 temp_idx[10000000];
static int cnt16[65536];
static u32 topFen[40000];
static u32 botFen[10001000];

static void radix3perm(int n) {
    u64 *a = keys, *b = temp;
    u32 *ia = idx, *ib = temp_idx;
    for (int shift = 0; shift < 48; shift += 16) {
        memset(cnt16, 0, sizeof(cnt16));
        for (int i = 0; i < n; i++) cnt16[(a[i] >> shift) & 0xFFFF]++;
        for (int i = 1; i < 65536; i++) cnt16[i] += cnt16[i-1];
        for (int i = n-1; i >= 0; i--) {
            int pos = --cnt16[(a[i] >> shift) & 0xFFFF];
            b[pos] = a[i]; ib[pos] = ia[i];
        }
        u64 *tk = a; a = b; b = tk;
        u32 *ti = ia; ia = ib; ib = ti;
    }
    if (a != keys) { memcpy(keys, a, (size_t)n*8); memcpy(idx, ia, (size_t)n*4); }
}

void count_2d(int n, const unsigned *x, const unsigned *y, unsigned *out) {
    for (int i = 0; i < n; i++) { keys[i] = ((u64)x[i] << 24) | y[i]; idx[i] = (u32)i; }
    radix3perm(n);

    int NB = n >> 8;
    int k = 0;
    while (k < n) {
        u32 cur_x = (u32)(keys[k] >> 24);
        int kk = k + 1;
        while (kk < n && (u32)(keys[kk] >> 24) == cur_x) kk++;
        for (int t = k; t < kk; ++t) {
            u32 yy = (u32)(keys[t] & 0xFFFFFFu);
            u32 b = yy >> 8, c = yy & 255;
            u32 s = 0;
            for (u32 j = b; j; j &= j - 1) s += topFen[j];
            u32 base = b << 8;
            for (u32 j = c; j; j &= j - 1) s += botFen[base + j];
            out[idx[t]] = s;
        }
        for (int t = k; t < kk; ++t) {
            u32 yy = (u32)(keys[t] & 0xFFFFFFu);
            u32 b = yy >> 8, c = yy & 255;
            u32 base = b << 8;
            for (u32 j = c + 1; j <= 256; j += j & -j) botFen[base + j]++;
            for (u32 j = b + 1; j <= (u32)NB; j += j & -j) topFen[j]++;
        }
        k = kk;
    }
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #11.607 s305 MB + 604 KBAcceptedScore: 100


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