hdu 1698

来源:互联网 发布:水泵选型软件 编辑:程序博客网 时间:2024/06/07 23:08

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;}
0 0
原创粉丝点击