题目链接: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】【2500】幸福的道路

    树形DP+单调队列优化DP 好题(也是神题……玛雅我实在是太弱了TAT,真是一个250) 完全是抄的zyf的……orz我还是退OI保平安吧 第一步对于每一天求出一个从第 i 个点出发走出去的最长链的长 ...

  2. Poj 2349 Arctic Network 分类: Brush Mode 2014-07-20 09:31 93人阅读 评论(0) 收藏

    Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9557   Accepted: 3187 De ...

  3. 获取iframe中的元素

    父窗口中获取iframe中的元素 var ifr = document.getElementById('suggustion').contentWindow.document.body; 在ifram ...

  4. CocoaPods 使用手册

    CocoaPods 使用手册 CocoaPods 使用手册                                                                        ...

  5. Kali-linux安装之后的简单设置

    1.更新软件源:修改sources.list文件:leafpad /etc/apt/sources.list然后选择添加以下适合自己较快的源(可自由选择,不一定要全部): #官方源deb http:/ ...

  6. Hadoop分布式配置

    本作品由Man_华创作,采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可.基于http://www.cnblogs.com/manhua/上的作品创作. 请先参照Linux安 ...

  7. associated 2 maps

    <!DOCTYPE html><html> <head> <meta http-equiv="Content-Type" content= ...

  8. BZOJ1083: [SCOI2005]繁忙的都市

    水题之王SP…这题就裸的最小生成树 /************************************************************** Problem: 1083 User ...

  9. 远程数据源Combobox

    Ext.define('bookInfo', {          extend: 'Ext.data.Model',//新类继承自model          fields: [{ name: 'b ...

  10. PHP-Java-Bridge的使用(平安银行支付功能专版)

    去年做平安银行的时候,用到了PHP-Java-Bridge,后来写了一篇博客记录使用PHP-Java-Bridge的一些心得(连接:http://my.oschina.net/kenblog/blog ...