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. [板子]ISAP

    ISAP求最大流,敲了一发板子,无压行,教程略去.转载请随意. #include <cstdio> #include <cstring> #include <algori ...

  2. MapControl控件AddLayer出现错误-引发类型为“System.Windows.Forms.AxHost+InvalidActiveXStateException”的异常

    出错代码: AxMapControl pMptrl = new AxMapControl(); //add data string mdbPath = string.Format("{0}\ ...

  3. 页内多个input全选不干扰且只用一段代码。

    //html内容 <body> <div id="d1"> <input type="checkbox" class=" ...

  4. PHP build notes - WARNING: This bison version is not supported for regeneration of the Zend/PHP parsers (found: 3.0, min: 204, excluded: 3.0).

     WARNING: This bison version is not supported for regeneration of the Zend/PHP parsers (found: 3.0, ...

  5. CSS实现文字省略

    1.首先给用于放文本的标签元素设置一个宽度值,并设置溢出属性overflow为溢出隐藏. width: 245px;/*一定要设置固定宽度*/ overflow: hidden;/*不显示超过对象尺寸 ...

  6. table:设置边距,td内容过长用省略号代替

    table:设置边距,td内容过长用省略号代替 1.table:设置边距 合并表格边框border-collapse: collapse,然后用th,td的padding设置内容和边框之间的空隙pad ...

  7. maven打包jar包

    参考http://www.cnblogs.com/justinzhang/p/4983633.html 新建jar类型的maven project (选择simple project ) 配置 < ...

  8. 利用django创建一个投票网站(六)

    建你的第一个 Django 项目, 第六部分 这一篇从第五部分(zh)结尾的地方继续讲起.再上一节中我们为网络投票程序编写了测试,而现在我们要为它加上样式和图片. 除了服务端生成的 HTML 以外,网 ...

  9. NFS服务器配置文档

    Server:192.168.1.206/WindowsClient:192.168.1.208/CentOS一.搭建windows NFS服务:1.安装NFS服务器:打开"服务管理器&qu ...

  10. 【原】小玩node+express爬虫-1

    最近开始重新学习node.js,之前学的都忘了.所以准备重新学一下,那么,先从一个简单的爬虫开始吧. 什么是爬虫 百度百科的解释: 爬虫即网络爬虫,是一种自动获取网页内容的程序.是搜索引擎的重要组成部 ...