poj 2777 Count Color 线段树区间更新
来源:互联网 发布:mysql text 最大长度 编辑:程序博客网 时间:2024/06/05 18:45
题目大意:
给你两种操作:
1、给一段连续区间涂颜色。
2、统计某一区间有多少种不同的颜色。
分析:
线段树区间更新,区间查询。略坑的一点是要用二进制优化,开始用的vector TLE到死。。。
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <vector>#include <set>#include <algorithm>#include <cstring>#define lson k<<1,l,mid#define rson k<<1|1,mid+1,rusing namespace std;const int maxn=1e5+5;int data[maxn*4];int cnt[maxn*4];void pushdown(int k){ if(cnt[k]){ data[k<<1]=data[k<<1|1]=data[k]; cnt[k<<1]=cnt[k<<1|1]=1;cnt[k]=0; }}void update(int k,int l,int r,int a,int b,int v){ if(a>r||b<l)return ; if(a<=l&&r<=b){cnt[k]=1;data[k]=1<<v;return ;} pushdown(k); int mid=l+r>>1; update(lson,a,b,v); update(rson,a,b,v); data[k]=data[k<<1|1]|data[k<<1];}int query(int k,int l,int r,int a,int b){ if(a>r||b<l){return 0;} if(a<=l&&r<=b){return data[k];} pushdown(k); int mid=l+r>>1; int t1=query(lson,a,b); int t2=query(rson,a,b); return t1|t2;}inline void read(int &z) { bool sig = false; char ch = getchar(); while (ch<'0' || ch>'9') {ch=='-'?sig=true:false;ch = getchar();} int x = ch - '0'; while ((ch = getchar()) >= '0'&&ch <= '9') x = x * 10 + ch - '0'; z = sig ? -x : x;}inline void out(int x){ if ( x > 9 ) out ( x / 10 ); putchar ( x % 10 + '0');}int main(){ int L,T,O; while(~scanf("%d%d%d",&L,&T,&O)){ int haha=min(L*8,maxn*4); for(int i=0;i<haha;i++){data[i]=1<<1;} fill(cnt,cnt+haha,0); for(int i=1;i<=O;i++){ int a,b,c; char p;scanf("\n%c",&p); if(p=='C'){ read(a),read(b),read(c); if(a>b)swap(a,b); update(1,1,L,a,b,c); } else{ read(a),read(b); if(a>b)swap(a,b); int t=query(1,1,L,a,b); int ans=0; for(int i=0;i<31;i++){ if(t&(1<<i))ans++; } out(ans);puts(""); } } } return 0;}
0 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 (线段树区间更新)
- POJ 2777 Count Color(线段树区间更新+状压)
- POJ 2777 Count Color(线段树区间更新)
- poj 2777 Count Color(线段树区间更新+技巧)
- POJ 2777 Count Color(线段树,区间更新,查询)
- POJ 2777 Count Color(线段染色 区间更新)
- poj 2777 Count Color 线段树成段更新区间统计
- POJ2777 Count Color 线段树区间更新
- POJ2777 Count Color 线段树区间更新
- 归并排序思想应用
- Java Web学习——问题罗列
- 回文串划分
- 高并发常见的解决方案
- 关于linux中使用vim打开文件出现^M的解决方法
- poj 2777 Count Color 线段树区间更新
- 自定义TextView显示指定行数
- MAC ping IP 地址(ping通/ping不通)
- Tomcat7配置数据源
- 自定义TextView处理任意时间长按短按的事件
- java G1垃圾收集器
- 关于使用公钥进行签名验证的代码
- ReactNative 学习(坑-Applocation xxxx has not been registered)
- workbench 连接mysql数据库失败