以下是题目大意:

有水平方向上很多块板子拼成的墙,一开始每一块都被涂成了颜色1,有C和P两个操作,代表的意思是:
C X Y Z —— 从X到Y将板子涂成颜色Z
P X Y    —— 查询X到Y的板子共有多少种颜色

            //有2块板子   两2颜色   4个询问
C
P
C
P

自己AC后上网查阅了许多别人的题解,看很多人用的什么“状态压缩”、“位运算”等等方法。感觉自己不会的知识还有很多。我用的方法是类似于hash的思想,每次将颜色查询时标记,由于这题的数据范围很小,不需要用离散化处理,所以比较好写。下面附上代码。

 /*********************************************/
/* author: Desgard_Duan */
/* motto : Everything is surprise for you! */
/*********************************************/ #include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <string>
#include <limits.h>
#include <vector>
#include <set>
#include <map> using namespace std; const int maxn = ;
int col[maxn << ], ans = ;
int Hash[]; void pushDown (int rt) {
if (col[rt]) {
col[rt * ] = col[rt * + ] = col[rt];
col[rt] = ;
}
} void build (int l, int r, int rt) {
col[rt] = ;
if (l == r) return ;
int m = (l + r) / ;
build (l, m, rt * );
build (m + , r, rt * + );
} void update (int L, int R, int c, int l, int r, int rt) {
if (L <= l && r <= R) {
col[rt] = c;
return ;
}
pushDown (rt);
int m = (l + r) / ;
if (L <= m) update (L, R, c, l, m, rt * );
if (m < R) update (L, R, c, m + , r, rt * + );
} void query (int L, int R, int l, int r, int rt) {
if (col[rt]) {
if (Hash[col[rt]] == ) {
ans ++;
Hash[col[rt]] = ;
}
return ;
}
int m = (l + r) / ;
if (m >= L) query (L, R, l, m, rt * );
if (m < R) query (L, R, m + , r, rt * + );
} int main () {
int L, T, O, x, y, z;
char op[];
while (~scanf ("%d%d%d", &L, &T, &O)) {
memset (col, , sizeof (col));
build (, L, );
while (O --) {
scanf ("%s%d%d", op, &x, &y);
if (x > y) swap (x, y);
if (op[] == 'C') {
scanf ("%d", &z);
update (x, y, z, , L, );
} else {
memset (Hash, , sizeof (Hash));
ans = ;
query (x, y, , L, );
printf ("%d\n", ans);
}
}
}
return ;
}

【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. Gson 基础教程 —— 自定义类型适配器(TypeAdapter)

    1,实现一个类型适配器(TypeAdapter) 自定义类型适配器需要实现两个接口: JsonSerializer<T> JsonDeserializer<T> 和两个方法: ...

  2. CornerStone 破解 最简单的破解方法

    方法一:最近在用cornerstone这个svn的软件感觉非常不错,但是竟然忘了破解,以至于到了14天试用期的最后一天才开始破解, 其实方法很简单,就是修高试用期的天数,找到plist文件把14天改为 ...

  3. 魅蓝Note2跑分 MT6753性能究竟如何

    MT6753实力究竟如何? 采用LP工艺的MT6753实际上在性能和功耗方面并不比MT6752高,相反,同频下功耗要高1/3左右.并且其内存带宽是5.3G/s,小于MT 6752的6.4G/s 而且没 ...

  4. djano-cms学习笔计(一)

    开放源码的内容管理系统,基于Web框架Django的. 优势如下 高度可扩展的插件系统,可让您自由地构建各种内容的网站. 前端编辑直接更改您的网站上的内容.工程的所有插件. 感谢可读的网址的页面结构是 ...

  5. Android学习之多点触摸并不神秘

    最近研究了一下多点触摸,写了个利用多点触摸来控制图片大小和单点触摸控制图片移动的程序,和大家分享分享. Android中监听触摸事件是onTouchEvent方法,它的参数为MotionEvent,下 ...

  6. Adobe/Flash Media Server 5.0 linux 64位系统下的安装

    一.下载 Adobe/Flash MS5.0下载地址: http://fs1.d-h.st/download/00036/VOt/adobemediaserver_5_ls1_linux64.tar. ...

  7. Win32<CreatFile>

    CreateFile函数详解 CreateFile The CreateFile function creates or opens the following objects and returns ...

  8. USB2.0速度识别

    我们知道USB2.0向下兼容USB1.x,即高速2.0的hub能支持所有的速度类型的设备,而USB1.x的hub不能支持高速设备(High Speed Device).因此,如果高速设备挂到USB1. ...

  9. iOS避免键盘遮挡输入方案

    项目中经常会遇到这样的问题:一个tableView中有大量的textField,当点击屏幕底部的textfield时,由于键盘弹出挡住了textfield输入框里的内容,造成很差的用户体验,如下图,点 ...

  10. HTML5 Canvas前台压缩图片并上传到服务器

    1.前台代码: <input id="fileOne" type="file" /> <input id="btnOne" ...