线段树专题—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 ...
随机推荐
- python的white循环
# _*_coding:utf-8 _*_import datetimename = 'gyf'passd = 123count =0now = datetime.datetime.now()whil ...
- 对 响应数据写在config文件的再次优化
之前写过 [基于moco的mock server 简单应用]这篇文章,然后自己这段时间也在做基金的接口测试,逛了一些论坛,然后对 响应数据写在config文件的再次优化,之前是把所有的响应数据都写到c ...
- app端性能测试笔记
IOS不清楚,我就说说android平台吧 1.按不同维度 APP级性能.代码级性能 app这一级 GT啊 emmage都可以检测 2.代码级性能的话 有可以分几块 函数性能UI ...
- LVS之-LAMP搭建wordpress
author:JevonWei 版权声明:原创作品 LVS搭建wordpress,涉及的知识点有DNS,LAMP,NFS及LVS 网络拓扑图 网络环境 NFS 192.168.198.130 mysq ...
- vue引入echarts、找不到的图表引入方法、图表中的点击事件
1.在vue-cli项目中添加webpack配置,本文引入的最新版本.在 3.1.1 版本之前 ECharts 在 npm 上的 package 是非官方维护的,从 3.1.1 开始由官方 EFE 维 ...
- 201521123081《Java程序设计》 第4周学习总结
1. 本周学习总结 1.1 尝试使用思维导图总结有关继承的知识点. 参考资料:百度脑图(上图为第3周实验学习总结中未展开部分) 1.2 使用常规方法总结其他上课内容. 多态.思维导图中有提及. 2. ...
- 201521123009 《Java程序设计》第12周学习总结
1. 本周学习总结 2. 书面作业 Q1:将Student对象(属性:int id, String name,int age,double grade)写入文件student.data.从文件读出显示 ...
- 201521123050 《Java程序设计》第14周学习总结
1. 本周学习总结 2. 书面作业 1. MySQL数据库基本操作 1.1立数据库,将自己的姓名.学号作为一条记录插入.(截图,需出现自己的学号.姓名) 在自己建立的数据库上执行常见SQL语句(截图) ...
- 201521123024 《java程序设计》 第12周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容.
- 201521123024 《Java程序设计》第11周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 2. 书面作业 本次PTA作业题集多线程 1.互斥访问与同步访问 完成题集4-4(互斥访问)与4-5(同步访问) ...