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. hihocoder-1014 Trie树

    hihocoder 1014 : Trie树 link: https://hihocoder.com/problemset/problem/1014 题意: 实现Trie树,实现对单词的快速统计. # ...

  2. windows批处理运行java程序

    明确需求 今天你编了一个java swing版照片查看器,想让计算机上的所有照片默认打开方式都改成你的照片查看器. 使用工具软件 很多工具软件都是不把jre打包到exe中的,这就是说打包之后的exe只 ...

  3. 查看mysql语句运行时间的2种方法

    网站运行很慢的时候,我就特别起知道为什么这么慢,所以我查啊查,数据库绝对是很重要的一部分,里面运行的sql是绝对不能放过的.平时做项目的时候,我也会注意sql语句的书写,写出一些高效的sql来,所以我 ...

  4. java-读取javabean类的set方法并设值

    /** * 新反射实例化模型 * @param filenamepath * @return */ public static Object newIntence(String filenamepat ...

  5. 学习Struts2的第一个应用步骤

    ---恢复内容开始--- 一.在官网 http://struts.apache.org/下载struts-2.3.31-all 1.  打开struts-2.3.31-all,将struts-2.3. ...

  6. 多条件分页查找(SQL拼接方法)

    def startTime=params.startTime+" 00:00:00"  def endTime=params.endTime + " 23:59:59&q ...

  7. 织梦DedeCMS

    DedeAMPZ服务器套件 http://dedeampz.dedecms.com/ DedeCMS  PHP开源网站管理系统  CMS系统 http://www.dedecms.com/produc ...

  8. 【BZOJ-2179&2194】FFT快速傅里叶&快速傅里叶之二 FFT

    2179: FFT快速傅立叶 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 2978  Solved: 1523[Submit][Status][Di ...

  9. 帝国cms内容页调用缩略图的原始尺寸图片

    在发布文章上传标题图片时,勾选"生成缩略图",将生成原图和对应的缩略图 原图的链接为[!--titlepic--]:/d/file/anlizhanshi/2016-11-25/8 ...

  10. AnjularJS系列4 —— 单个页面加载多个ng-App

    第四篇,插播, 单个页面加载多个ng-App 在写范例的时候发现的问题 一个页面有多个ng-app,angular只会处理第一个ng-app 需要加载两个ng-app,需要进行手动加载: angula ...