poj 2777
来源:互联网 发布:php软件环境是什么 编辑:程序博客网 时间:2024/06/06 03:31
题目
用了二进制中1的个数来统计不同的颜色数
最后在求解时用0来与这个数中的1或,统计颜色个数
仍然是区间更新,区间询问
代码如下:
#include<cstdio>#include<iostream>using namespace std;#define maxn 100010#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1struct Tree{ int l,r,col,lazy;}tree[maxn<<2];int ans;void PushUp(int rt){ tree[rt].col=tree[rt<<1].col|tree[rt<<1|1].col;}void PushDown(int rt){ if(tree[rt].lazy){ tree[rt<<1].lazy=tree[rt<<1|1].lazy=tree[rt].lazy; tree[rt<<1].col=tree[rt<<1|1].col=tree[rt].col; tree[rt].lazy=0; }}void build(int l,int r,int rt){ tree[rt].l=l; tree[rt].r=r; tree[rt].lazy=0; if(l==r) return ; int m=(l+r)>>1; build(lson); build(rson);}void update(int x,int y,int col,int rt){ int l,r; l=tree[rt].l; r=tree[rt].r; if(l==x&&r==y){ tree[rt].col=col; tree[rt].lazy=1; return ; } PushDown(rt); int m=(l+r)>>1; if(x<=m) update(x,min(m,y),col,rt<<1); if(y>m) update(max(m+1,x),y,col,rt<<1|1); PushUp(rt);}void query(int x,int y,int rt){ int l,r; l=tree[rt].l; r=tree[rt].r; if(l==x&&r==y){ ans=ans|tree[rt].col; return ; } PushDown(rt); int m=(l+r)>>1; if(x<=m) query(x,min(m,y),rt<<1); if(y>m) query(max(m+1,x),y,rt<<1|1);}int main(){ int i,j,n,q,x,y,z,cnt,num; char str[5]; while(scanf("%d%d%d",&n,&num,&q)!=EOF) { build(1,n,1); update(1,n,1,1); while(q--) { scanf("%s",str); scanf("%d%d",&x,&y); if (x>y) { swap(x,y); } if (str[0]=='C') { scanf("%d",&z); update(x,y,1<<(z-1),1); } else { ans=0; query(x,y,1); cnt=0; for (i=0;i<num;i++) { if ((ans & (1<<i))!=0) cnt++; } printf("%d\n",cnt); } } } return 0;}
- poj 2777
- poj 2777
- poj 2777
- poj 2777
- poj 2777
- POJ 2777
- POJ 2777
- poj-2777
- poj 2777
- poj 2777
- POJ 2777
- poj 2777
- poj 2777
- poj 2777
- Poj 2777
- poj 2777
- poj 2777
- POJ-2777
- dedecms更新时报模板不存在,无法解析
- bochs & nasm的安装
- [python脚本]爬blackhat官网的paper
- STL中对vector容器中的结构体进行排序
- java设计模式---状态模式
- poj 2777
- Binder进程通信介绍
- 用Python写Exploit
- 比较Java和C++的几个修饰符
- Ubuntu搭建hadoop单机版伪分布环境
- KMP算法
- USB枚举过程
- [python脚本]一个简单的web爬虫(1)
- Lowest Common Multiple Plus