hdu 1698

hdu 1689


线段树区间染色,听说用map可以水过去。


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>

const int MAXN = 1000005;

int tree[MAXN<<2];

int n , q;

int tot;

inline void fold_down(const int si)
{
    if(tree[si] != false)
      tree[si<<1] = tree[(si<<1)|1] = tree[si];

    tree[si] =  false;
}

inline void update(const int &v,const int l,const int r,const int ll,const int rr,const int si)
{
    if(l == ll && r == rr)
    {
       fold_down(si);    

       tree[si] = v;    
    }
    else
    {
        int mid = (ll + rr)>>1;

        fold_down(si);

        if(r <= mid)      update(v,l,r,ll,mid,si<<1);
        else if(l > mid)  update(v,l,r,mid+1,rr,(si<<1)|1);
        else
        {
            update(v,l,mid,ll,mid,(si<<1));
            update(v,mid+1,r,mid+1,rr,(si<<1)|1);
        }
    }

}

inline void count(const int ll,const int rr,const int si)
{
    if(ll == rr)
    {
        tot += tree[si];
    }
    else
    {
        int mid = (ll + rr)>>1;

        fold_down(si);

        count(ll,mid,si<<1);
        count(mid+1,rr,(si<<1)|1);
    }

}
int main()
{
    int T , num=0;

#ifndef ONLINE_JUDGE    
    freopen("hdu1698.in","r",stdin);
    freopen("hdu1698.out","w",stdout);
#endif

     scanf("%d",&T);

     while(T--)
     {
         ++ num;

         memset(tree,0,sizeof(tree));

        scanf("%d",&n);    

          tree[1] = 1;

          scanf("%d",&q);

          while(q--)
          {
              int a , b , c;

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

              update(c,a,b,1,n,1);
          }

         tot=0;

         count(1,n,1);

         printf("Case %d: The total value of the hook is %d.\n",num,tot);
     }



#ifndef ONLINE_JUDGE
    fclose(stdin);
    fclose(stdout); 
#endif
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值