#include <stdio.h>
#include <string.h>

const int MAXN = 100005;

typedef struct {
    int cnt;
    int l;
    int r;
}Node;

Node seg[3 * MAXN];
int ans[MAXN];

void build(int idx,int l,int r)
{
    seg[idx].l = l;
    seg[idx].r = r;
    seg[idx].cnt = 0;

    if ( l == r )
        return;

    int mid = ( l + r ) >> 1;
    build(idx << 1, l, mid);
    build((idx << 1) + 1, mid + 1, r);
}

void color(int idx,int l,int r)
{
    if ( seg[idx].l == l && seg[idx].r == r )
    {
        seg[idx].cnt++;
        return;
    }

    int mid = ( seg[idx].l + seg[idx].r ) >> 1;
    if ( r <= mid )
        color(idx << 1, l, r);
    else if ( mid + 1 <= l )
        color((idx << 1 ) + 1, l, r);
    else
    {
        color(idx << 1, l, mid );
        color((idx << 1 ) + 1, mid + 1, r);
    }
}

void solve(int idx)
{
    for (int i = seg[idx].l; i <= seg[idx].r; i++)
        ans[i] += seg[idx].cnt;

    if ( seg[idx].l == seg[idx].r )
        return;

    solve(idx << 1);
    solve((idx << 1 ) + 1);
}

int main()
{
//    freopen("1.txt","r",stdin);

    int N;
    while ( scanf("%d",&N) == 1 )
    {
        memset(ans, 0, sizeof(ans));
        memset(seg, 0, sizeof(seg));

        if ( N == 0 )
            break;
        
        build(1,1,N);
        int p,q;

        for (int i = 0; i < N; i++)
        {
            scanf("%d%d",&p,&q);
            color(1,p,q);
        }

        solve(1);

        for ( i = 1; i <= N; i++)
            printf("%d%c",ans[i], ( i == N ) ? '\n' : ' ' );

    }

    return 0;
}

 

posted on 2013-06-22 17:21  Sinker  阅读(240)  评论(0编辑  收藏  举报