记录编号 571855 评测结果 AWAAAAWWEE
题目名称 孙伯符降临 最终得分 50
用户昵称 Gravatarcb 是否通过 未通过
代码语言 C++ 运行时间 0.595 s
提交时间 2022-06-25 15:50:49 内存使用 3.06 MiB
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
int n, N = 0;
int ans[100005] = {0};
int c[100005] = {0};

int lowbit (int x) {
    return (x & -x);
}

void add (int x, int y) {
    for (;x <= N; x += lowbit (x)) {
        c[x] += y;
    }
}

int ask (int x) {
    int a = 0;
    for (; x; x -= lowbit (x)) a += c[x];
    return a;
}

struct node {
    int a, b, x;
} p[100005];

bool cmp (node r1, node r2) {
    if (r1.a == r2.a) {
        return r1.b < r2.b;
    }
    else return r1.a < r2.a;
}



int main () {
    freopen ("sunbofu.in", "r", stdin);
    freopen ("sunbofu.out", "w", stdout);
    scanf ("%d", &n);
    for (int q = 1; q <= n; ++q) {
        scanf ("%d %d", &p[q].a, &p[q].b);
        N = max (N, p[q].b);
        p[q].x = q;
    }
    sort (p + 1, p + n + 1, cmp);
//    for (int q = 1; q <= n; ++q) {
//        printf ("%d %d\n", p[q].a, p[q].b);
//    }
    for (int q = 1; q <= n; ++q) {
        ans[p[q].x] = ask (p[q].b);
        add (p[q].b, 1);
//        for (int w = 1; w <= n; ++w) {
//            printf ("%d", c[q]);
//        }
//        printf ("\n");
    }
    for (int q = 1; q <= n; ++q) printf ("%d\n", ans[q]);
    return 0;
}