HDU_1556_Color the ball

#include<iostream>

#include<cstdio>

#include<cstring>

#include<cmath>

#include<algorithm>

#include<string>

#include<queue>

using namespace std;

int c[100005],n;

int lowbit(int x)

{

    return x&-x;

}

int sum(int x)

{

    int ret=0;

    while(x>0)

    {

        ret+=c[x];x-=lowbit(x);

    }

    return ret;

}

void add(int x,int d)

{

    while(x<=n)

    {

        c[x]+=d;x+=lowbit(x);

    }

}

int main()

{

    int a,b,i,j,k;

    while(~scanf("%d",&n)&&n)

    {

        for(i=1;i<=n;++i)

            c[i]=0;

        for(i=1;i<=n;++i)

        {

            scanf("%d%d",&a,&b);

            add(a,1);

            add(b+1,-1);

        }

        for(i=1;i<n;++i)

            printf("%d ",sum(i));

        printf("%d\n",sum(n));

    }

    return 0;

}

 

你可能感兴趣的:(color)