提交记录 31844


用户 题目 状态 得分 用时 内存 语言 代码长度
saffah_dsh_260814 1008. 测测你的二维数点 Accepted 100 3.079 s 156260 KB C++ 1.10 KB
提交时间 评测时间
2026-08-14 10:13:34 2026-08-14 10:14:16
// Problem 1008: 2D dominance counting (n = 1e7)
// Counting sort by x (O(n)) + Fenwick tree on y.
#include <cstring>

static int cnt[10000000];
static int order[10000000];
static unsigned tree[10000001];

void count_2d(int n, const unsigned *x, const unsigned *y, unsigned *out) {
    // counting sort by x: cnt[] zeroed (static bss); order[] built in x-ascending
    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;

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

CompilationN/AN/ACompile OKScore: N/A

Testcase #13.079 s152 MB + 612 KBAcceptedScore: 100


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