poj-2352

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
#define maxn 110000
struct list
{
    int l,r;
    int x;
}node[maxn*6];
struct listt
{
    int x,y;
    bool friend operator < (const listt a, const listt b)
    {
        if(a.x!=b.x)return a.x<b.x;
        return a.y<b.y;
    }
}point[maxn];
void build(int l,int r,int st)
{
    node[st].l=l;
    node[st].r=r;
    node[st].x=0;
    if(l!=r)
    {
        build(l,(l+r)/2,st*2);
        build((l+r)/2+1,r,st*2+1);
    }
}
void insert(int x,int st)
{

    int l=node[st].l;
    int r=node[st].r;
    if(l>x||r<x)return;
    if(l==r)
    {
        node[st].x++;
        return ;
    }
    insert(x,st*2);
    insert(x,st*2+1);
    node[st].x=node[st*2].x+node[st*2+1].x;
}
int search(int l,int r,int st)
{
    int ll=node[st].l;
    int rr=node[st].r;
    if(ll>r||rr<l)return 0;
    if(l<=ll&&rr<=r)return node[st].x;
    return search(l,r,st*2)+search(l,r,st*2+1);
}
int lvl[maxn];
int main()
{
    int i,n;
    while(~scanf("%d",&n))
    {
        memset(lvl,0,sizeof(lvl));
        for(i=0;i<n;i++)
        {
            scanf("%d%d",&point[i].x,&point[i].y);
        }
        sort(point,point+n);
        build(0,40000,1);
        for(i=0;i<n;i++)
        {
            int t=search(0,point[i].y,1);
            lvl[t]++;
            insert(point[i].y,1);
        }
        for(i=0;i<=n-1;i++)
        {
            printf("%d\n",lvl[i]);
        }
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值