提交记录 33740


用户 题目 状态 得分 用时 内存 语言 代码长度
saffah_dsh_260814 1008. 测测你的二维数点 Accepted 100 2.699 s 273448 KB C++ 1.33 KB
提交时间 评测时间
2026-08-14 22:31:42 2026-08-14 22:31:52
// Problem 1008: 2D dominance counting (n = 1e7)
// Counting sort by x -> gather contiguous ysort/idxsort/xsort -> Fenwick sweep.
#include <cstring>

static int cnt[10000000];
static int order[10000000];
static unsigned ysort[10000000];
static int idxsort[10000000];
static unsigned xsort[10000000];
static unsigned tree[10000001];

void count_2d(int n, const unsigned *x, const unsigned *y, unsigned *out) {
    // counting sort by x
    for (int i = 0; i < n; ++i) cnt[x[i]]++;
    for (int i = 1; i < n; ++i) cnt[i] += cnt[i - 1];
    for (int i = 0; i < n; ++i) order[--cnt[x[i]]] = i;

    // gather contiguous arrays (makes sweep's y/x/idx reads sequential)
    for (int k = 0; k < n; ++k) {
        int ii = order[k];
        ysort[k] = y[ii];
        idxsort[k] = ii;
        xsort[k] = x[ii];
    }

    // sweep in x order; within one x-bucket: query all, then update all
    int k = 0;
    while (k < n) {
        unsigned cur_x = xsort[k];
        int kk = k + 1;
        while (kk < n && xsort[kk] == cur_x) kk++;
        for (int t = k; t < kk; ++t) {
            unsigned s = 0;
            for (unsigned j = ysort[t]; j; j &= j - 1) s += tree[j];
            out[idxsort[t]] = s;
        }
        for (int t = k; t < kk; ++t) {
            for (unsigned j = ysort[t] + 1; j <= (unsigned)n; j += j & -j) tree[j]++;
        }
        k = kk;
    }
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #12.699 s267 MB + 40 KBAcceptedScore: 100


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