poj 2777 Count Color
2012-08-05 18:20
375 查看
http://poj.org/problem?id=2777
一个坑爹的错误找了我半天,脑残呀!我用的数状态压存储的,加上延迟标记下就行了
一个坑爹的错误找了我半天,脑残呀!我用的数状态压存储的,加上延迟标记下就行了
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #define maxn 555555 using namespace std; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 typedef long long ll; ll d[maxn<<2]; bool col[maxn<<2]; void pushdown(int rt) { if(col[rt]) { col[rt<<1]=1; col[rt<<1|1]=1; d[rt<<1]=d[rt]; d[rt<<1|1]=d[rt]; col[rt]=0; } } void update(int L,int R,int C,int l,int r,int rt) { //cout<<l<<" "<<r<<" "<<rt<<endl; if(L<=l&&R>=r) { d[rt]=(1LL)<<C; col[rt]=1; // 注意把它赋值为1 return; } pushdown(rt); int m=(l+r)>>1; if(L<=m) update(L,R,C,lson); if(R>m) update(L,R,C,rson); d[rt]=d[rt<<1]|d[rt<<1|1]; } ll query(int L,int R,int l,int r,int rt) { if(L<=l&&R>=r) return d[rt]; pushdown(rt); int m=(l+r)>>1; ll ret1=0,ret2=0; if(L<=m) ret1=query(L,R,lson); if(R>m) ret2=query(L,R,rson); return ret1|ret2; } int main() { int T,L,Q,l,r,c; char ord[5]; while(scanf("%d%d%d",&L,&T,&Q)==3) { memset(col,0,sizeof(col)); d[1]=1; col[1]=1; while(Q--) { scanf("%s",ord); if(ord[0]=='C') { scanf("%d %d %d",&l,&r,&c); if(l>r) swap(l,r); update(l,r,c-1,1,L,1); } else { scanf("%d %d",&l,&r); if(l>r) swap(l,r); ll ans=query(l,r,1,L,1); int cnt=0; for(int i=0;i<T;i++) if(ans&((1LL)<<i)) cnt++; printf("%d\n",cnt); } } } return 0; }
相关文章推荐
- 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思想)
- 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(位运算+线段树区间更新 可用bitset记录)
- POJ 2777 Count Color 线段树 区间更新
- POJ 2777 Count Color(线段树+二进制位运算)
- POJ 2777Count Color (线段树区间更新 + 位运算压缩)
- POJ 2777 Count Color
- HOJ 2685 POJ 2777 Count Color