xfstart07
Get busy living or get busy dying

#include < iostream >
using   namespace  std;

struct  Node{
    
int  l,r;
    
int  cover;
}tree[
400000 ];
int  L,T,N;
bool  color[ 31 ];
int  ans;
void  build( int  Num, int  l, int  r){
    tree[Num].l
= l;
    tree[Num].r
= r;
    tree[Num].cover
= 1 ;
    
if (l < r){
        
int  mid = (l + r) >> 1 ;
        build(Num
* 2 ,l,mid);
        build(Num
* 2 + 1 ,mid + 1 ,r);
    }
}
void  insert( int  Num, int  l, int  r, int  col){
    
if (l <= tree[Num].l && r >= tree[Num].r || tree[Num].cover == col){
        tree[Num].cover
= col;
        
return ;
    }
    
if (tree[Num].cover > 0 ){
        tree[Num
* 2 ].cover = tree[Num].cover;
        tree[Num
* 2 + 1 ].cover = tree[Num].cover;
    }
    tree[Num].cover
=- 1 ;
    
int  mid = (tree[Num].l + tree[Num].r) >> 1 ;
    
if (r <= mid) insert(Num * 2 ,l,r,col);
    
else   if (l > mid) insert(Num * 2 + 1 ,l,r,col);
    
else {
        insert(Num
* 2 ,l,r,col);
        insert(Num
* 2 + 1 ,l,r,col);
    }
}
void  query( int  Num, int  l, int  r){
    
if (tree[Num].cover > 0 ){
        
if ( ! color[tree[Num].cover]){
            color[tree[Num].cover]
= 1 ;
            ans
++ ;
        }
        
return ;
    }
    
int  mid = (tree[Num].l + tree[Num].r) >> 1 ;
    
if (r <= mid) query(Num * 2 ,l,r);
    
else   if (l > mid) query(Num * 2 + 1 ,l,r);
    
else {
        query(Num
* 2 ,l,mid);
        query(Num
* 2 + 1 ,mid + 1 ,r);
    }
}
int  main()
{
    scanf(
" %d%d%d " , & L, & T, & N);
    getchar();
    build(
1 , 1 ,L);
    
int  a,b,c;
    
char  ch;
    
for ( int  i = 1 ;i <= N; ++ i){
        scanf(
" %c " , & ch);
        
if (ch == ' C ' ){
            scanf(
" %d%d%d " , & a, & b, & c);
            insert(
1 ,a,b,c);
        }
        
else {
            scanf(
" %d%d " , & a, & b);
            memset(color,
0 , sizeof (color));
            ans
= 0 ;
            query(
1 ,a,b);
            printf(
" %d\n " ,ans);
        }
        getchar();
    }
    
return   0 ;
}



posted on 2009-04-27 10:56 xfstart07 阅读(109) 评论(0)  编辑 收藏 引用 所属分类: 代码库

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理