http://poj.org/problem?id=2777

前几天看到一个大神说,要搞,就搞专题或者套题,我觉得现在这么菜的我,还是搞搞专题吧。

一道比较裸也比较基础的线段树的题目。

题意:就是有一段木头,可以对这个木头进行两种操作,一是进行涂色,而是进行查询,如果一个木头之前涂过色,那么之后涂色的话,会对之前的进行覆盖。

很明显的一个线段树的题目,不用线段树肯定超时的。

 #include <stdio.h>
#include <string.h>
#define maxn 1000005 struct note{
int l,r;
int col;
}Tegtree[ *maxn ];
bool mark[]; void bulid(int root,int st,int en)
{
Tegtree[ root ].l = st;
Tegtree[ root ].r = en;
if(st == en) return ;
int mid = ( Tegtree[ root ].l + Tegtree[ root ].r )>>;
bulid( root << , st , mid );
bulid( (root << ) + , mid + , en );
} void Update(int root,int x,int y,int colc)
{
if(Tegtree[ root ].l >= x && Tegtree[ root ].r <=y )
{
Tegtree[ root ].col = colc;
return ;
} else
{
if(Tegtree[root].col > ) //进行延迟标记。
{
Tegtree[ root << ].col = Tegtree[root].col;
Tegtree[( root << ) + ].col = Tegtree[root].col;
Tegtree[root].col = ;
}
int mid = (Tegtree[ root ].l + Tegtree[ root ].r ) >> ;
if(x>mid){
Update((root<<)+,x,y,colc);
}else if(y<=mid){
Update(root<<,x,y,colc);
}else {
Update(root<<,x,mid,colc);
Update((root<<)+,mid+,y,colc);
}
}
}
void Find(int root,int x,int y)
{
if(Tegtree[root].col > )
{
mark[Tegtree[root].col] = true;
}else{
int mid = (Tegtree[ root ].l + Tegtree[ root ].r ) >> ;
if(x>mid){
Find((root<<)+,x,y);
}else if(y<=mid){
Find(root<<,x,y);
}else {
Find(root<<,x,mid);
Find((root<<)+,mid+,y);
}
}
} int main()
{
// freopen("in.txt","r",stdin);
int l,t,o,a,b,c;
char tmp[];
while(scanf("%d%d%d",&l,&t,&o)!=EOF)
{
Tegtree[].col = ;
bulid(,,l);
while(o--)
{ scanf("%s",tmp);
// printf("%s\n",tmp);
if(tmp[]=='C')
{
scanf("%d%d%d",&a,&b,&c);
getchar();
Update(,a,b,c);
}
else if(tmp[]=='P')
{
scanf("%d%d",&a,&b);
getchar();
memset(mark,false,sizeof(mark));
Find(,a,b);
int ans = ;
for(int i = ; i <= ; i++)
if(mark[i]) ans++;
printf("%d\n",ans);
}
}
}
return ;
}

POJ2777的更多相关文章

  1. poj2777(线段树)

    题目链接:https://vjudge.net/problem/POJ-2777 题意:有L块连续的板子,每块板子最多染一种颜色,有T种(<=30)颜色,刚开始将所有板子染成颜色1,O次操作(包 ...

  2. poj-2777线段树刷题

    title: poj-2777线段树刷题 date: 2018-10-16 20:01:07 tags: acm 刷题 categories: ACM-线段树 概述 这道题是一道线段树的染色问题,,, ...

  3. Count Color poj2777 线段树

    Count Color poj2777 线段树 题意 有一个长木板,现在往上面在一定区间内刷颜色,后来刷的颜色会掩盖掉前面刷的颜色,问每次一定区间内可以看到多少种颜色. 解题思路 这里使用线段树,因为 ...

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

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

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

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

  6. poj2777 线段树

    //Accepted 4768 KB 391 ms //线段树,延时标记的应用 //对于每一段,用一个int表示被着色的情况,change标记该段的颜色是否发生整体的改变,即这一段 //用没用被全部涂 ...

  7. [POJ2777]Count Color(线段树)

    题目链接:http://poj.org/problem?id=2777 给你一个长为L想线段,向上面染色,颜色不超过30种,一共有O次操作,操作有两种: C a b c 在[a,b]上染上c颜色 P ...

  8. Count Color POJ--2777

    Count Color Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 32217   Accepted: 9681 Desc ...

  9. 【POJ2777】Count Color(线段树)

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

随机推荐

  1. http 413 wcf

    在网上搜到413的解决办法有多种,看具体项目找到对应的解决办法 如果是wcf返回的413,与serverRuntime无关,只要在Binding中设置最大接收值即可, <binding name ...

  2. php use memcached in ubuntu 14.04

    I assume you already had a lamp environment first step,we must to install memched in our Ubuntu Syst ...

  3. 以.net core重构原有.net framework过程中的一些API变更记录(持续更新)

    1)Type.IsGenericType类似属性变更 以下是.net framework 4.5中Type抽象类中泛型类型的几个个属性,用于泛型类型的相关信息判断: 以下是.net core(nets ...

  4. VS2013编译google protobuf 出现问题error C3861: “min”:

    问题描述: 今天用vs2013编译protobuf 2.4.1 报错: 错误 3 error C3861: "max": 找不到标识符 f:\google\protobuf\pro ...

  5. Java常见Exception整理

    前言: 技术开发入坑近1年,摸打滚爬,各种升级打怪.因目前从事Java相关,故整理了一下并把常见的异常(Exception)贴出来,一来为了后续提醒自己,二来供即将入坑的朋友打一下预防针!A级(代码逻 ...

  6. pycharm5注册码

    43B4A73YYJ-eyJsaWNlbnNlSWQiOiI0M0I0QTczWVlKIiwibGljZW5zZWVOYW1lIjoibGFuIHl1IiwiYXNzaWduZWVOYW1lIjoiI ...

  7. SpringMVC前后端数据交互总结

    控制器 作为控制器,大体的作用是作为V端的数据接收并且交给M层去处理,然后负责管理V的跳转.SpringMVC的作用不外乎就是如此,主要分为:接收表单或者请求的值,定义过滤器,跳转页面:其实就是ser ...

  8. Win7硬盘整数分区一览表

    10G=10245 MB 20G=20482 MB 30G=30726 MB 40G=40963 MB 50G=51208 MB 60G=61444 MB 70G=71681 MB 80G=81926 ...

  9. IntelliJ IDEA mac 快捷键

    cmd+O 查找类alt+cmd+O 符号shift+cmd+O 查找文件^+space 补全alt + F7 查找符号的使用情况F1 查看文档cmd+b 跳转定义,或者 鼠标+ctrlcmd+F12 ...

  10. [Java] JSP笔记 - Filter 过滤器

    一.什么是Web过滤器 Servlet API 很久以前就已成为企业应用开发的基石,而 Servlet 过滤器则是对 J2EE 家族的相对较新的补充. Servlet 过滤器是可插入的 Web 组件, ...