POJ2777
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的更多相关文章
- poj2777(线段树)
题目链接:https://vjudge.net/problem/POJ-2777 题意:有L块连续的板子,每块板子最多染一种颜色,有T种(<=30)颜色,刚开始将所有板子染成颜色1,O次操作(包 ...
- poj-2777线段树刷题
title: poj-2777线段树刷题 date: 2018-10-16 20:01:07 tags: acm 刷题 categories: ACM-线段树 概述 这道题是一道线段树的染色问题,,, ...
- Count Color poj2777 线段树
Count Color poj2777 线段树 题意 有一个长木板,现在往上面在一定区间内刷颜色,后来刷的颜色会掩盖掉前面刷的颜色,问每次一定区间内可以看到多少种颜色. 解题思路 这里使用线段树,因为 ...
- Count Color(线段树+位运算 POJ2777)
Count Color Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 39917 Accepted: 12037 Descrip ...
- [poj2777] Count Color (线段树 + 位运算) (水题)
发现自己越来越傻逼了.一道傻逼题搞了一晚上一直超时,凭啥子就我不能过??? 然后发现cin没关stdio同步... Description Chosen Problem Solving and Pro ...
- poj2777 线段树
//Accepted 4768 KB 391 ms //线段树,延时标记的应用 //对于每一段,用一个int表示被着色的情况,change标记该段的颜色是否发生整体的改变,即这一段 //用没用被全部涂 ...
- [POJ2777]Count Color(线段树)
题目链接:http://poj.org/problem?id=2777 给你一个长为L想线段,向上面染色,颜色不超过30种,一共有O次操作,操作有两种: C a b c 在[a,b]上染上c颜色 P ...
- Count Color POJ--2777
Count Color Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 32217 Accepted: 9681 Desc ...
- 【POJ2777】Count Color(线段树)
以下是题目大意: 有水平方向上很多块板子拼成的墙,一开始每一块都被涂成了颜色1,有C和P两个操作,代表的意思是:C X Y Z —— 从X到Y将板子涂成颜色ZP X Y —— 查询X到Y的板子共 ...
随机推荐
- Connect to Office365
How to connect to office365 1. Connect to Exchange Online $UserCredential = Get-Credential $Session ...
- .net的一致性哈希实现
最近在项目的微服务架构推进过程中,一个新的服务需要动态伸缩的弹性部署,所有容器化示例组成一个大的工作集群,以分布式处理的方式来完成一项工作,在集群中所有节点的任务分配过程中,由于集群工作节点需要动态增 ...
- Android基础测试题(二)
今天给大家带来的是Android基础测试题(二) 题目要求: 定义一个5位长度的整型数组并初始化,然后构建方法根据用户传入的数字判断是否存在数组中,如果存在,返回所在位置,如果不存在,返回-1 首先第 ...
- 小猪cms之怎样查询绑定的微网站模板
微网站内容页面url g=Wap&m=Index&a=content (g=Wap)模块路径对应路径:\PigCms\Lib\Action\Wap (m=Index)控制文件对应文件: ...
- iframe的sandbox使用
sandbox:限制iframe的权限,解决安全性问题. 定义 如果被规定为空字符串(sandbox=""),sandbox 属性将会启用一系列对行内框架中内容的额外限制.sand ...
- Sonar安装配置
https://www.sonarqube.org/downloads/ 下载sonar.当前版本为6.2 解压压缩包,进行配置: 修改sonarqube-6.2\conf\sonar.propert ...
- ITShare
框架底层通过IBatis和XML实现ORM映射: 业务处理类似UI,通过Controller和JavaScript交互: 视图通过Castle与NVelocity实现,jquery.tmpl渲染: . ...
- php跳转页面
1.header(location:'url'); header函数前面不能有输出 ! 可以先输出到缓存. 2js echo "<script language='javascript ...
- orpsocv2 从ROM(bootrom)启动分析--以atlys板子的启动为例子
1 复位后的启动地址 1) 复位后,启动地址在or1200_defines.v最后宏定义,atlys板子的目录:orpsocv2\boards\xilinx\atlys\rtl\verilog\inc ...
- Lattice Reduction (LLL) 算法C代码实现
废话不多说,大名鼎鼎的Lenstra-Lenstra-Lovasz(LLL) 算法.实现参考论文:Factoring Polynomials with Rational Coefficients, 作 ...