POJ 2777 Count Color(线段树+位运算)
来源:互联网 发布:大数据泄露 编辑:程序博客网 时间:2024/06/06 12:28
更新的时候要用延迟标记,用位运算保存儿子结点合并的结果,强大啊.
#include <iostream>#include <memory.h>#include <cstdio>using namespace std;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1const int maxn=100010;int segs[maxn*3],L,T,O;bool f[maxn*3];char buf[5];void build(int l,int r,int rt){segs[rt]=1;f[rt]=0;if(l==r)return;int m=(l+r)>>1;build(lson),build(rson);}void pushDown(int rt){if(f[rt]){f[rt<<1]=f[rt<<1|1]=f[rt];segs[rt<<1]=segs[rt];segs[rt<<1|1]=segs[rt];f[rt]=0;}}void update(int C,int L,int R,int l,int r,int rt){if(L<=l&&r<=R){segs[rt]=C;f[rt]=1;return;}pushDown(rt);int m=(l+r)>>1;if(L<=m)update(C,L,R,lson);if(R>m)update(C,L,R,rson);segs[rt]=segs[rt<<1]|segs[rt<<1|1];}int query(int L,int R,int l,int r,int rt){if(L<=l&&r<=R){return segs[rt];}pushDown(rt);int m=(l+r)>>1,ret=0;if(L<=m)ret|=query(L,R,lson);if(R>m)ret|=query(L,R,rson);return ret;}int main(){scanf("%d%d%d",&L,&T,&O);build(1,L,1);while (O--){scanf("%s",buf);if(buf[0]=='C'){int A,B,C;scanf("%d%d%d",&A,&B,&C);if(A>B)swap(A,B);update(1<<(C-1),A,B,1,L,1);}else {int A,B;scanf("%d%d",&A,&B);if(A>B)swap(A,B);int ans=0,ret=query(A,B,1,L,1);for (int i=0;ret;ret>>=1){if(1&ret)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 线段树区间更新位运算
- POJ 2777 Count Color (线段树+位运算)
- POJ 2777 Count Color(线段树+位运算)
- poj 2777 Count Color(线段树、状态压缩、位运算)
- POJ 2777 Count Color(线段树+位运算)
- POJ 2777 Count Color ( 线段树&&位运算
- hdu5023A Corrupt Mayor's Performance Art(线段树+位运算) poj 2777Count Color(线段树+位运算)
- Count Color(线段树+位运算 POJ2777)
- Count Color(线段树+位运算)
- POJ 2777 Count Color(位运算+线段树+lazy+区间更新)
- POJ 2777 Count Color 【线段树 区间更新 按位或运算】
- POJ 2777 Count Color(线段树区间修改+位运算)
- poj 2777 Count Color(线段树+lazy优化+位运算)
- POJ 2777Count Color (线段树区间更新 + 位运算压缩)
- Weka学习 Apriori算法if( !m_car)
- C++拷贝构造函数(深拷贝,浅拷贝)参考二
- Revit 2014 API新功能网络视频讲座 5月14号下午14:30(可下载讲座视频)
- Objectvie-C XML解析
- UVA 10305 Ordering Tasks
- POJ 2777 Count Color(线段树+位运算)
- cglib动态代理_讲解
- 推荐 2013 年最新的 10 款 jquery 插件
- php为什么函数方法名大小写不敏感
- zf异常处理机制
- Flex与后台(Java)交互
- C# 图片加水印、防盗链接图片 案例
- jquery实现ajax联动框
- android开发步步为营之4:客户端通过http和服务端进行交互