HDU1556-Color the ball

http://acm.hdu.edu.cn/showproblem.php?pid=1556

#include<cstdio>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define MAX 100001
int tree[MAX<<2];; 
void build(int l,int r,int rt)
{
    tree[rt]=0;
    if(l==r) 
       return;
    int m=(l+r)>>1;
    build(lson);
    build(rson);
}
void update(int L,int R,int l,int r,int rt)
{
    if(L<=l&&R>=r)
    {
        tree[rt]++;
        return;
    }
    int m=l+r>>1;
    if(L<=m)
       update(L,R,lson);
    if(R>m)
       update(L,R,rson);
}
int query(int p,int l,int r,int rt)
{
    if(l==r)
       return tree[rt];
    if(tree[rt]>0)
    {
        tree[rt<<1]+=tree[rt];
        tree[rt<<1|1]+=tree[rt];
        tree[rt]=0;
    }
    int m=(l+r)>>1;
    if(p<=m) 
       return query(p,lson);
    if(p>m) 
       return query(p,rson);
}
int main(void)
{
    int N,a,b,i;
    while(scanf("%d",&N),N)
    {
        build(1,N,1);
        for(i=1;i<=N;i++)
        {
            scanf("%d%d",&a,&b);
            update(a,b,1,N,1);
        }
        for(i=1;i<N;i++) 
           printf("%d ",query(i,1,N,1));
        printf("%d\n",query(N,1,N,1));
    }
    return 0;
}

转载于:https://www.cnblogs.com/YogurtShen/archive/2012/08/31/2665023.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值