题目链接: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. ACM--South Pacific 2012

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=5 ...

  2. 【bzoj1014】[JSOI2008]火星人prefix

    1014: [JSOI2008]火星人prefix Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 6031  Solved: 1917[Submit] ...

  3. mysql导出导入某张表

    一般表数据少的话都用图形界面了,看着比较方便. 如果表中数据比较多,用图形界面极容易卡死,这个时候就要用到命令行了. 用命令行导出导入大量数据还是比较快的,方法如下: 导出库db1中的表table1: ...

  4. spring.net +dapper 打造简易的DataAccess 工具类.

    public class DBUtil { /// <summary> /// 数据库连接字符串 /// </summary> private static string Da ...

  5. 制作一个可以给team所有成员用的开发者证书

    1. 将证书的private key导出一个.p12的文件给别人 2. 从apple developer网站下载证书对应的provisioning profile 待优化

  6. NumPy的array

    1.numpy包中的array数组,用于弥补列表可以存储任意的数据类型的不足,因为有时候我们需要存储某种类型的数据在数组中,这才是数组的本来内涵.我们通过向numpy.array()函数中传递pyth ...

  7. 思考 ”前端开发人员都在关注的 GitHub 资源“

    点这里 原文: 资源 免费的计算机编程类中文书籍 免费编程书籍 计算机科学论文 codeparkshare Python初学者书籍.视频.资料.社区推荐 Python资料汇总 app应用推荐 码农周刊 ...

  8. JDBC 程序的常见错误及调试方法

    详细介绍:http://dev.mysql.com/doc/refman/5.5/en/error-handling.html http://dev.mysql.com/doc/refman/5.5/ ...

  9. github研究

    一个程序猿一定会用git,但是我还没怎么用过,平时真是懒啊,学习之!...

  10. Android 注入详解

    Android下的注入的效果是类似于Windows下的dll注入,关于Windows下面的注入可以参考这篇文章Windows注入术.而Android一般处理器是arm架构,内核是基于linux,因此进 ...