【POJ】2777 Count Color
2012-05-22 17:29
267 查看
#include<cstdio> #include<cstring> #define MAXN 100010 int cnt; struct node { int bit,val; }; node tree[MAXN<<2]; inline void swap(int &x,int &y) { int temp=x; x=y; y=temp; } inline void PushUp(int rt) { tree[rt].bit=tree[rt<<1].bit|tree[rt<<1|1].bit; } inline void PushDown(int rt) { if(tree[rt].val) { tree[rt<<1]=tree[rt<<1|1]=tree[rt]; tree[rt].val=0; } } void Update(int x,int y,int val,int L,int R,int rt) { if(x<=L&&R<=y) { tree[rt].val=val; tree[rt].bit=1<<(val-1); } else { int mid=(L+R)>>1; PushDown(rt); if(mid>=x) Update(x,y,val,L,mid,rt<<1); if(y>mid) Update(x,y,val,mid+1,R,rt<<1|1); PushUp(rt); } } void Query(int x,int y,int L,int R,int rt) { if(x<=L&&R<=y) cnt|=tree[rt].bit; else { int mid=(L+R)>>1; PushDown(rt); if(mid>=x) Query(x,y,L,mid,rt<<1); if(y>mid) Query(x,y,mid+1,R,rt<<1|1); } } int main() { char ch; int n,t,q,a,b,c,ans,i; while(~scanf("%d%d%d",&n,&t,&q)) { memset(tree,0,sizeof(tree)); Update(1,n,1,1,n,1); while(q--) { scanf(" %c%d%d",&ch,&a,&b); if(a>b) swap(a,b); if(ch=='C') { scanf("%d",&c); Update(a,b,c,1,n,1); } else { cnt=0; Query(a,b,1,n,1); for(i=ans=0;i<t;i++) { if(cnt&(1<<i)) ans++; } printf("%d\n",ans); } } } return 0; }
相关文章推荐
- POJ:2777-Count Color(线段树+状压)
- poj 2777 Count Color
- POJ 题目2777 Count Color(线段树,区间查询染色数)
- POJ 2777 Count Color 线段树入门题
- POJ 2777 Count Color (线段树、lazy思想)
- poj 2777 count color解题报告【线段树】
- POJ 2777 Count Color (线段树区间更新)
- POJ 2777 Count Color
- POJ 2777 Count Color(线段树+懒惰标记)
- poj_2777 Count Color(线段树染色)
- POJ 2777 Count Color
- POJ 2777 Count Color (线段树的区间更新+lazy tag)
- POJ训练计划2777_Count Color(线段树/成段更新/区间染色)
- POJ 2777 Count Color (线段树)
- POJ-2777-Count Color
- POJ 2777 Count Color (线段树&位运算)
- POJ 2777 Count Color
- POJ 2777 Count Color(线段树+位运算)
- Poj 2777 Count Color
- POJ 2777 Count Color