比赛 SBOI2022暑假快乐赛① 评测结果 AAAAAAWWWW
题目名称 孙伯符降临 最终得分 60
用户昵称 yrtiop 运行时间 0.107 s
代码语言 C++ 内存使用 4.43 MiB
提交时间 2022-06-25 10:53:35
显示代码纯文本
#include <bits/stdc++.h>
#define mp make_pair
#define fir first
#define sec second
#define pb emplace_back
using namespace std;
const int maxn = 1e5 + 5;
const int maxm = 1e6 + 5;
int c[maxm],cnt;
int lowbit(int x) {
    return x & -x;
}
void add(int x,int y) {
    for(;x <= cnt;x += lowbit(x))c[x] += y;
    return ;
}
int query(int x) {
    int ans = 0;
    for(;x;x -= lowbit(x))ans += c[x];
    return ans;
}
struct node {
    int x,y,id;
    node() {
        x = y = id = 0;
    }
    node(int x,int y,int id):x(x),y(y),id(id){}
}a[maxn];
int f[maxn],n;
int main() {
    freopen("sunbofu.in","r",stdin);
    freopen("sunbofu.out","w",stdout);
    scanf("%d",&n);
    for(int i = 1;i <= n;++ i) {
        scanf("%d%d",&a[i].x,&a[i].y);
        a[i].id = i;
        cnt = max(a[i].y , cnt);
    }
    sort(a + 1 , a + 1 + n , [](node p,node q){return (p.x ^ q.x) ? p.x < q.x : ((p.y ^ q.y) ? p.y < q.y : p.id > q.id);});
    for(int i = 1;i <= n;++ i) {
        f[a[i].id] = query(a[i].y);
        add(a[i].y , 1);
    }
    for(int i = 1;i <= n;++ i)printf("%d\n",f[i]);
    fclose(stdin);
    fclose(stdout);
    return 0;
}