题目链接:http://poj.org/problem?id=2777

给你一个长为L想线段,向上面染色,颜色不超过30种,一共有O次操作,操作有两种:

C a b c 在[a,b]上染上c颜色

P a b 查询[a,b]上所有颜色数。

思路:线段树维护每个线段上颜色种类,用位来存颜色。好题。

 /*
━━━━━┒ギリギリ♂ eye!
┓┏┓┏┓┃キリキリ♂ mind!
┛┗┛┗┛┃\○/
┓┏┓┏┓┃ /
┛┗┛┗┛┃ノ)
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┃┃┃┃┃┃
┻┻┻┻┻┻
*/
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath>
using namespace std;
#define fr first
#define sc second
#define cl clear
#define BUG puts("here!!!")
#define W(a) while(a--)
#define pb(a) push_back(a)
#define Rint(a) scanf("%d", &(a))
#define Rll(a) scanf("%I64d", &a)
#define Rs(a) scanf("%s", a)
#define Cin(a) cin >> a
#define FRead() freopen("in", "r", stdin)
#define FWrite() freopen("out", "w", stdout)
#define Rep(i, len) for(int i = 0; i < (len); i++)
#define For(i, a, len) for(int i = (a); i < (len); i++)
#define Cls(a) memset((a), 0, sizeof(a))
#define Clr(a, x) memset((a), (x), sizeof(a))
#define Full(a) memset((a), 0x7f, sizeof(a))
#define lrt rt << 1
#define rrt rt << 1 | 1
#define pi 3.14159265359
#define RT return
#define lowbit(x) x & (-x)
#define onenum(x) __builtin_popcount(x)
typedef long long LL;
typedef long double LD;
typedef unsigned long long Uint;
typedef pair<int, int> pii;
typedef pair<LL, LL> pLL;
typedef pair<string, LL> psi;
typedef map<string, LL> msi;
typedef vector<LL> vi;
typedef vector<LL> vl;
typedef vector<vl> vvl;
typedef vector<bool> vb; #define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
const int maxn = ;
int sum[maxn<<];
int add[maxn<<];
int L, T, O; void pushUP(int rt) {
sum[rt] = sum[lrt] | sum[rrt];
} void pushDOWN(int rt) {
if(add[rt] != -) {
sum[lrt] = sum[rrt] = ( << add[rt]);
add[lrt] = add[rrt] = add[rt];
add[rt] = -;
}
} void build(int l, int r, int rt) {
sum[rt] = ; add[rt] = ;
if(l == r) return;
int m = (l + r) >> ;
build(l, m, lrt);
build(m+, r, rrt);
} void update(int L, int R, int c, int l, int r, int rt) {
if(L <= l && r <= R) {
add[rt] = c;
sum[rt] = << c;
return;
}
pushDOWN(rt);
int m = (l + r) >> ;
if(L <= m) update(L, R, c, lson);
if(m < R) update(L, R, c, rson);
pushUP(rt);
} int query(int L, int R, int l, int r, int rt) {
if(L <= l && r <= R) return sum[rt];
pushDOWN(rt);
int m = (l + r) >> ;
int ret = ;
if(L <= m) ret |= query(L, R, lson);
if(m < R) ret |= query(L, R, rson);
return ret;
} int main() {
// FRead();
char cmd[];
int l, r, c;
while(~scanf("%d%d%d", &L, &T, &O)) {
build(, L, );
W(O) {
Rs(cmd);
if(cmd[] == 'C') {
scanf("%d%d%d",&l,&r,&c);
if(l > r) swap(l, r);
update(l, r, c, , L, );
}
else {
scanf("%d%d",&l,&r);
if(l > r) swap(l, r);
int p = query(l, r, , L, );
int ret = ;
while(p) {
if(p & ) ret++;
p >>= ;
}
printf("%d\n", ret);
}
}
}
RT ;
}

[POJ2777]Count Color(线段树)的更多相关文章

  1. [poj2777] Count Color (线段树 + 位运算) (水题)

    发现自己越来越傻逼了.一道傻逼题搞了一晚上一直超时,凭啥子就我不能过??? 然后发现cin没关stdio同步... Description Chosen Problem Solving and Pro ...

  2. POJ2777 Count Color 线段树区间更新

    题目描写叙述: 长度为L个单位的画板,有T种不同的颜料.现要求按序做O个操作,操作分两种: 1."C A B C",即将A到B之间的区域涂上颜色C 2."P A B&qu ...

  3. Count Color(线段树+位运算 POJ2777)

    Count Color Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 39917 Accepted: 12037 Descrip ...

  4. POJ 2777 Count Color(线段树之成段更新)

    Count Color Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 33311 Accepted: 10058 Descrip ...

  5. poj 2777 Count Color(线段树)

    题目地址:http://poj.org/problem?id=2777 Count Color Time Limit: 1000MS   Memory Limit: 65536K Total Subm ...

  6. poj 2777 Count Color(线段树区区+染色问题)

    题目链接:  poj 2777 Count Color 题目大意:  给出一块长度为n的板,区间范围[1,n],和m种染料 k次操作,C  a  b  c 把区间[a,b]涂为c色,P  a  b 查 ...

  7. poj 2777 Count Color(线段树、状态压缩、位运算)

    Count Color Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 38921   Accepted: 11696 Des ...

  8. poj 2777 Count Color - 线段树 - 位运算优化

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 42472   Accepted: 12850 Description Cho ...

  9. POJ P2777 Count Color——线段树状态压缩

    Description Chosen Problem Solving and Program design as an optional course, you are required to sol ...

  10. POJ 2777 Count Color (线段树成段更新+二进制思维)

    题目链接:http://poj.org/problem?id=2777 题意是有L个单位长的画板,T种颜色,O个操作.画板初始化为颜色1.操作C讲l到r单位之间的颜色变为c,操作P查询l到r单位之间的 ...

随机推荐

  1. BZOJ 3223 文艺平衡树 [codevs3303翻转区间]

    AC通道:http://www.lydsy.com/JudgeOnline/problem.php?id=3223 通道2:http://codevs.cn/problem/3303/ 题目分析: 我 ...

  2. Java获取项目中的路径 分类: Java Game 2014-08-14 10:17 122人阅读 评论(0) 收藏

    在项目中经常需要获取某个文件的路径: 在这里提供一些获取路径的方法.. 1.此种方式获取的路径,是当前类所在的路径: UserDAOTest.class.getResource("UserD ...

  3. objc swift 混编

    原链接:http://blog.csdn.net/xuanwenchao/article/details/30226823 在xocde6出来我们大部分代码都是用objective-c写的(部分C/C ...

  4. int型整数的数值范围

    假设int型用两个字节表示对于有符号的整数,用补码表示的话,最高位是符号位,后面15位用来表示数据.1.正数,表示的范围为0000 0000 0000 0001-0111 1111 1111 1111 ...

  5. Sqli-labs less 52

    Less-52 和less50是一样的,只是这里的mysql错误不会在前台显示,但是对于stacked injection是一样的利用方式 http://127.0.0.1/sqli-labs/Les ...

  6. 分布式数据存储 - MySQL主从复制高可用方案

    前面几篇文章说道MySQL数据库的高可用方案主从复制.主从复制的延迟产生原因.延迟检测及延迟解决方案(并未从根本上解决),这种主从复制方案保证数据的冗余的同时可以做读写分离来分担系统压力但是并非是高可 ...

  7. Codeforces 475D CGCDSSQ(分治)

    题意:给你一个序列a[i],对于每个询问xi,求出有多少个(l,r)对使得gcd(al,al+1...ar)=xi. 表面上是询问,其实只要处理出每个可能的gcd有多少个就好了,当左端点固定的时候,随 ...

  8. HDU 1558 Segment set (并查集+线段非规范相交)

    题目链接 题意 : 如果两个线段相交就属于同一集合,查询某条线段所属集合有多少线段,输出. 思路 : 先判断与其他线段是否相交,然后合并. #include <cstdio> #inclu ...

  9. Linux多线程之互斥

    题目 共要卖票20张,由命令行输入窗口数,由线程模拟窗口.每卖掉一张票,屏幕显示由几号窗口所卖,一并显示剩余票数 思路 由于票数 ticket_cnt 是全局变量,因此每当一个线程将其减一(卖出一张票 ...

  10. JS面向(基于)对象编程--构造方法(函数)

    构造函数(方法)介绍 什么是构造函数呢?在回答这个问题之前,我们来看一个需求:前面我们在创建人类的对象时,是先把一个对象创建好后,再给他的年龄和姓名属性赋值,如果现在我要求,在创建人类的对象时,就直接 ...