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 ...
随机推荐
- Octave Tutorial(《Machine Learning》)之第一课《数据表示和存储》
Octave Tutorial 第一课 Computation&Operation 数据表示和存储 1.简单的四则运算,布尔运算,赋值运算(a && b,a || b,xor( ...
- iOS开发RunLoop
最近处于离职状态,时间也多了起来,但是学习还是不能放松,今天总结一下RunLoop,RunLoop属于iOS系统层的东西,还是比较重要的. 一.什么是RunLoop 字面意思看是跑圈,也可以看作运行循 ...
- 关于Tarjan(3)——离线LCA
LCA(最近公共祖先),指对于一棵树上任意两个节点往上走最早都能到达的节点. 求LCA有两种方法,一种是倍增,另一种则是Tarjan........ Tarjan巧妙利用并查集的思想: 这里的Tarj ...
- SQL AlawaysOn 之三:SQL服务器加入域
声明:由于第一篇,配置域服务器,用的是别人的图,所以那个IP并不是我的. 至此为止,我的域控制器IP为192.168.8.230 域名为:dataserver.com 约定的SQL1 IP为192. ...
- SQLServer 数据库不能重命名的解决方案
无法用排他锁锁定该数据库,以执行该操作 SQL Server2008 因为可能其他用户在占用着该数据库 解决办法为 把数据库先改为单用户的,再改数据库名,再改回多用户的 USE [master] GO ...
- 原生ajax 和jquery ajax 个人总结
AJAX:即“Asynchronous Javascript And XML”(异步JavaScript和XML),是指一种创建交互式网页应用的网页开发技术. 通过在后台 ...
- 获取 metadata 过程详解 - 每天5分钟玩转 OpenStack(167)
接上节,启动 neutron router 后 instance c1 终于拿到了 metadata, 从下面 c1 的启动日志可知: c1 所认为的 metadata 服务地址是 169.254.1 ...
- Windows 10 Creaters Update 新功能——画中画模式和窗口高斯模糊
在Windows 10 Creaters Update中,可以给窗口设置高斯模糊了,只要几行代码! <Grid Loaded="Grid_Loaded"> <Gr ...
- try{} catch(…){} 讨论(转)
以前都是用try{} catch(…){}来捕获C++中一些意想不到的异常, 今天看了Winhack的帖子才知道,这种方法在VC中其实是靠不住的.例如下面的代码: .try .{ .BYTE* pch ...
- Python__slots__详解
摘要 当一个类需要创建大量实例时,可以通过__slots__声明实例所需要的属性, 例如,class Foo(object): __slots__ = ['foo'].这样做带来以下优点: 更快的属性 ...