线段树专题—ZOJ1610 Count the Colors(涂区间,直接tag标记)
Painting some colored segments on a line, some previously painted segments may be covered by some the subsequent ones.
Your task is counting the segments of different colors you can see at last.
Input
The first line of each data set contains exactly one integer n, 1 <= n <= 8000, equal to the number of colored segments.
Each of the following n lines consists of exactly 3 nonnegative integers separated by single spaces:
x1 x2 c
x1 and x2 indicate the left endpoint and right endpoint of the segment, c indicates the color of the segment.
All the numbers are in the range [0, 8000], and they are all integers.
Input may contain several data set, process to the end of file.
<b< dd="">
Output
Each line of the output should contain a color index that can be seen from the top, following the count of the segments of this color, they should be printed according to the color index.
If some color can't be seen, you shouldn't print it.
Print a blank line after every dataset.
<b< dd="">
Sample Input
5
0 4 4
0 3 1
3 4 2
0 2 2
0 2 3
4
0 1 1
3 4 1
1 3 2
1 3 1
6
0 1 0
1 2 1
2 3 1
1 2 0
2 3 0
1 2 1
Sample Output
1 1
2 1
3 1
1 1
0 2
1 1
题意:就是在一段区间涂成一种颜色,然后最后问你,每种颜色涂成了多少种不同颜色。
题解:注意一下范围所有都是8000,所以和hdu1698差不了太多,也是区间标记,根
的优先值大于儿子的,这样就是这道题的解法,最后一次总的询问,将color 1-8000染好
颜色,然后就处理一下就好了。
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<climits>
using namespace std;
const int MAXN=;
bool a[MAXN]={};
int b[MAXN]={},n,num=,color[MAXN],tree[MAXN*]={},x,y,z;
void change(int l,int r,int p,int x,int y,int zhi)
{
if (l>r) return;
if (l==x&&r==y) tree[p]=zhi;
else
{
if (tree[p]!=-)
{
tree[p*]=tree[p*+]=tree[p];
tree[p]=-;
}
int mid=(l+r)>>;
if (y<=mid) change(l,mid,p*,x,y,zhi);
else if (x>=mid+) change(mid+,r,p*+,x,y,zhi);
else
{
change(l,mid,p*,x,mid,zhi);
change(mid+,r,p*+,mid+,y,zhi);
}
}
}
void query(int l,int r,int p){
if (l>r) return;
if (tree[p]!=-)
{
for (int i=l;i<=r;i++)
color[i]=tree[p];
}
else
{
if (l==r) return;
int mid=(l+r)>>;
query(l,mid,p*);
query(mid+,r,p*+);
}
}
int main()
{
while (~scanf("%d",&n))
{
num=;
for (int i=;i<MAXN*;i++)
tree[i]=-;
for (int i=;i<MAXN;i++)
a[i]=b[i]=,color[i]=MAXN-;
for (int i=;i<=n;i++)
{
scanf("%d%d%d",&x,&y,&z);
if (x!=y) change(,,,x+,y,z);
}
query(,,);
for (int i=;i<=;i++)
if (color[i]!=color[i-]) a[color[i]]=,b[color[i]]++;
for (int i=;i<MAXN-;i++)
{
if (a[i]) cout<<i<<" "<<b[i]<<endl;
}
cout<<endl;
}
}
线段树专题—ZOJ1610 Count the Colors(涂区间,直接tag标记)的更多相关文章
- 线段树专题—ZOJ1610 Count the Colors
题意:给一个n,代表n次操作,接下来每次操作表示把[l.r]区间的线段涂成k的颜色当中,l,r,k的范围都是0到8000 分析:事实上就是拿线段树维护一段区间的颜色,整体用到的是线段树的区间更新把,可 ...
- kuangbin专题七 ZOJ1610 Count the Colors (灵活线段树)
Painting some colored segments on a line, some previously painted segments may be covered by some th ...
- zkw线段树专题
题目来自大神博客的线段树专题 http://www.notonlysuccess.com/index.php/segment-tree-complete/ hdu1166 敌兵布阵题意:O(-1)思路 ...
- vj线段树专题
vj线段树专题题解 单点更新模板 void build(int x,int l,int r){//sum[x]控制l-r区域 if(l==r){Sum[x]=num[l];return ;} int ...
- [ZOJ1610]Count the Colors(线段树,区间染色,单点查询)
题目链接:http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=1610 题意:给一个长8000的绳子,向上染色.一共有n段被染色,问染 ...
- Kuangbin 带你飞-线段树专题 题解
HDU 1166 敌兵布阵 单调更新区间查询和 #include <map> #include <set> #include <list> #include < ...
- 2018 UESTC 线段树专题
A - 一棵简单的线段树 A[1...n]初始全为0. 1. 给两个数p 和 x(1≤p≤n),单点更新 A[p] <- x 2. 给两个数L和R (1≤L<R≤n), L到R区间里这几 ...
- [ZOJ1610]Count the Colors
Description 画一些颜色段在一行上,一些较早的颜色就会被后来的颜色覆盖了. 你的任务就是要数出你随后能看到的不同颜色的段的数目. Input 每组测试数据第一行只有一个整数n, 1 < ...
- 线段树专题 POJ3468 A Simple Problem with Integers
题意:n个点.m个操作.两种操作类型.C X Y K 表示区间[x,y]上每一个点值加k.Q X Y 求区间[x,y]的和 分析:线段树区间求和,裸模板 注意:结果会超int,要用long long ...
随机推荐
- Ibatis组合键关联查询
在使用Ibatis时,会经常遇到关联查询,一般有两种解决方案: 使用代码进行关联查询 使用Ibatis配置文件进行关联查询 使用代码进行关联查询不作解释,本次主要是针对Ibatis配置文件进行关联查询 ...
- 实现点击后创建div,若对div2秒无操作则将div隐藏,鼠标移上div让它不隐藏,移出div超过两秒则div隐藏
$('.addLabel').on('click', function () { setTimeout(function(){ if(hoverflag==0){ $(".labelHide ...
- ios 初体验<真机调试>
1.很多小伙伴,初学ios后面,都想迫不及待的连接上真机,在真机上调试,本人今天花了许久时间,在网上查了许多资料,一直出现了个问题导致我没法真机调试, 问题一:Your session has exp ...
- [js高手之路]Vue2.0基于vue-cli+webpack Vuex用法详解
在这之前,我已经分享过组件与组件的通信机制以及父子组件之间的通信机制,而我们的vuex就是为了解决组件通信问题的 vuex是什么东东呢? 组件通信的本质其实就是在组件之间传递数据或组件的状态(这里将数 ...
- nhibernate教程(4)--条件查询(Criteria Query)
NHibernate之旅(4):探索查询之条件查询(Criteria Query) 2008-10-16 18:20 by 李永京, 44341 阅读, 43 评论, 收藏, 编辑 本节内容 NHi ...
- cobbler部署安装CentOS6.8
Linux运维:cobbler : 矮哥linux运维群:93324526 学习cobbler的话,必须先搞懂kickstart,原理不是,不懂如何排错. kickstart部署请点击这里 1. Co ...
- 团队作业8——第二次项目冲刺(Beta阶段)--5.24 forth day
团队作业8--第二次项目冲刺(Beta阶段)--5.24 forth day Day four: 会议照片 项目进展 Beta冲刺的第四天,以下是今天具体任务安排: 队员 昨天已完成的任务 今日计划完 ...
- 201521123070 《JAVA程序设计》第4周学习总结
1. 本章学习总结 1.1 尝试使用思维导图总结有关继承的知识点. http://naotu.baidu.com/file/4de6f42e4f4f6cce0531dd9997b04e60?token ...
- 【干货】教你如何利用fullPage.js以及move.js插件打造高端大气的网站效果!
前言: 如今我们经常能见到全屏网站,尤其是国外网站.这些网站用几幅很大的图片或色块做背景,再添加一些简单的内容,显得格外的高端大气上档次. 在学习过jQuery插件之后,才发现之前的很多网站特效完全可 ...
- Java 最常用类(前1000名) 来自GitHub 3000个项目
这篇文章主要介绍了最常用的1000个Java类(附代码示例),需要的朋友可以参考下 分析Github 3000个开源项目,粗略统计如下.括号内的数字是使用频率 0-3000. 下面的列表显示不全,完整 ...