zoj1610线段树区间覆盖
链接https://vjudge.net/contest/66989#problem/F
坑爹的线段树,一直用区间更新做,做了半天一点眉目都没有,只好搜题解,感觉好堕落,经常不会做就搜题解,以后一定要慢慢克服
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
const int maxn=;
ll value[maxn<<],vis[maxn<<];
void pushdown(int rt)//向下更新
{
if(value[rt]!=-)
{
value[rt<<]=value[rt<<|]=value[rt];//只要向下更新
value[rt]=-;
}
}
void update(int L,int R,int c,int l,int r,int rt)
{
if(L<=l&&r<=R)//区间更新
{
value[rt]=c;
return ;
}
if(value[rt]==c)return ;
if(value[rt]!=-)pushdown(rt);
int m=(l+r)>>;
if(L<=m)update(L,R,c,ls);
if(R>m)update(L,R,c,rs);
}
void query(int l,int r,int rt)
{
if(value[rt]>=)//也有可能是l==r
{
for(int i=l;i<=r;i++)
vis[i]=value[rt];//vis【i】记录i处的颜色
return ;
}
if(l!=r&&value[rt]==-)
{
int m=(l+r)>>;
query(ls);
query(rs);
}
}
int main()
{
int n,ans[];
while(~scanf("%d",&n)){
memset(ans,,sizeof(ans));
memset(vis,-,sizeof(vis));
memset(value,-,sizeof(value));//因为0也算一种颜色,所以初始化-1
for(int i=;i<=n;i++)
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
update(a+,b,c,,,);//不能用0到8000处理
}
query(,,);
int i=;
while(i<maxn){
int color=vis[i],j=i+;
if(vis[i]==-){i++;continue;}//没有颜色
while(vis[j]!=-&&vis[j]==color&&j<maxn)j++;//向前推进直到下一个颜色出现
ans[color]++;
i=j;
}
for(int i=;i<=;i++)
if(ans[i])
printf("%d %d\n",i,ans[i]);
printf("\n");
}
return ;
}
zoj1610线段树区间覆盖的更多相关文章
- HDU 4509 湫湫系列故事——减肥记II(线段树-区间覆盖 或者 暴力技巧)
http://acm.hdu.edu.cn/showproblem.php?pid=4509 题目大意: 中文意义,应该能懂. 解题思路: 因为题目给的时间是一天24小时,而且还有分钟.为了解题方便, ...
- [NOI2015] 软件包管理器【树链剖分+线段树区间覆盖】
Online Judge:Luogu-P2146 Label:树链剖分,线段树区间覆盖 题目大意 \(n\)个软件包(编号0~n-1),他们之间的依赖关系用一棵含\(n-1\)条边的树来描述.一共两种 ...
- Mayor's posters POJ - 2528 线段树区间覆盖
//线段树区间覆盖 #include<cstdio> #include<cstring> #include<iostream> #include<algori ...
- POJ - 2528Mayor's posters (离散化+线段树区间覆盖)
The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign h ...
- POJ 2528 Mayor's posters (线段树+区间覆盖+离散化)
题意: 一共有n张海报, 按次序贴在墙上, 后贴的海报可以覆盖先贴的海报, 问一共有多少种海报出现过. 题解: 因为长度最大可以达到1e7, 但是最多只有2e4的区间个数,并且最后只是统计能看见的不同 ...
- 线段树区间覆盖 蛤玮打扫教室(zzuli 1877)
http://acm.zzuli.edu.cn/zzuliacm/problem.php?id=1877 Description 现在知道一共有n个机房,算上蛤玮一共有m个队员,教练做了m个签,每 ...
- HDU1698 Just a Hook(线段树&区间覆盖)题解
Problem Description In the game of DotA, Pudge’s meat hook is actually the most horrible thing for m ...
- Mayor's posters 线段树区间覆盖
题目链接 http://poj.org/problem?id=2528 Description The citizens of Bytetown, AB, could not stand that t ...
- HDU 1698 Just a Hook(线段树区间覆盖)
线段树基本操作练习,防手生 #include <cstdio> #include <cstring> #include <cstdlib> #define lson ...
随机推荐
- mybatis基础学习1---(配置文件和sql语句)
1:配置文件(主要配置文件) 2:配置文件(引入) 3:sql语句解析: <mapper namespace="/"> <!-- 1 -->根据id查对象 ...
- 2017java预备作业2
1 安装git • 到Git官网https://www.git-scm.com/ 下载Git客户端 • 安装时选择默认即可. • 安装完成后在桌面的快捷菜单中选择Git Bash Here 或者在开始 ...
- background-size IE8兼容方案
根据canius(http://caniuse.com/#search=background-size),background-size兼容性为IE9以及以上浏览器,如下图所示. 实例代码: < ...
- CCS内存数据转成图片
在嵌入式DSP图像处理开发过程中,经常需要将DSP内存中的图像数据保存下来,作为数据集.CCS5.4或者CCS3.3都只支持保存内存原始数据而不支持将内存数据直接存储为一张图片,为了能将CCS保存的. ...
- 【树莓派】制作树莓派最小镜像:img裁剪瘦身
制作树莓派镜像,可以参考这篇文章:http://blog.csdn.net/talkxin/article/details/50456282 摘录部分要点内容如下(如果作者不允许转载,请联系即删除): ...
- 解决ubuntu更新中断后报错问题
今天在更新ubuntu的时候,更新了一半被我强制关闭了,就报错了 当再使用sudo apt-get update命令时出现了dpkg was interrupted,you must manually ...
- windows系统下安装composer
使用安装程序安装 这是将 Composer 安装在你机器上的最简单的方法. 下载并且运行 Composer-Setup.exe,它将安装最新版本的 Composer 安装完成后,将composer的b ...
- 解决mac os下mcss命令报错:env: node\r: No such file or directory
标题无“转载”即原创文章,版权所有.转载请注明来源:http://besteam.im/blogs/article/31/. 我一直对字符界面有抵触感,即使会用vim,我的linux脚本(python ...
- 第2章Zabbix基础进阶
p.MsoNormal,li.MsoNormal,div.MsoNormal { margin: 0cm; margin-bottom: .0001pt; text-align: justify; t ...
- FB,Flash,as3 Bug集
一.Flash builder 报错 当导入3.0的项目时运行出现如下错误: 进程已终止,没有建立到调试器的连接.error while loading initial content 启动命令详细信 ...