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标记)的更多相关文章

  1. 线段树专题—ZOJ1610 Count the Colors

    题意:给一个n,代表n次操作,接下来每次操作表示把[l.r]区间的线段涂成k的颜色当中,l,r,k的范围都是0到8000 分析:事实上就是拿线段树维护一段区间的颜色,整体用到的是线段树的区间更新把,可 ...

  2. kuangbin专题七 ZOJ1610 Count the Colors (灵活线段树)

    Painting some colored segments on a line, some previously painted segments may be covered by some th ...

  3. zkw线段树专题

    题目来自大神博客的线段树专题 http://www.notonlysuccess.com/index.php/segment-tree-complete/ hdu1166 敌兵布阵题意:O(-1)思路 ...

  4. vj线段树专题

    vj线段树专题题解 单点更新模板 void build(int x,int l,int r){//sum[x]控制l-r区域 if(l==r){Sum[x]=num[l];return ;} int ...

  5. [ZOJ1610]Count the Colors(线段树,区间染色,单点查询)

    题目链接:http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=1610 题意:给一个长8000的绳子,向上染色.一共有n段被染色,问染 ...

  6. Kuangbin 带你飞-线段树专题 题解

    HDU 1166 敌兵布阵 单调更新区间查询和 #include <map> #include <set> #include <list> #include < ...

  7. 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区间里这几 ...

  8. [ZOJ1610]Count the Colors

    Description 画一些颜色段在一行上,一些较早的颜色就会被后来的颜色覆盖了. 你的任务就是要数出你随后能看到的不同颜色的段的数目. Input 每组测试数据第一行只有一个整数n, 1 < ...

  9. 线段树专题 POJ3468 A Simple Problem with Integers

    题意:n个点.m个操作.两种操作类型.C X Y K 表示区间[x,y]上每一个点值加k.Q X Y 求区间[x,y]的和 分析:线段树区间求和,裸模板 注意:结果会超int,要用long long ...

随机推荐

  1. java Io流中FileInputStream和BufferedInputStream的速度比较

    首先是对FileInputStream 加上 FileOutputStream 对文件拷贝的应用 我这里拷贝的是一个视频.当然,你们拷贝什么都可以,当文件越大时效果越明显 下面是对BufferedIn ...

  2. Spark Submit 脚本

    当我们需要命令行传递参数时候,将--class 写在前面,然后是jar 最后是参数 spark-submit --master yarn --num-executors 3 --executor-me ...

  3. C#:委托(delegate)和事件(event) (转)

    委托(delegate): 它是C#语言里面的函数指针,代表可以指向某一个函数,在运行的时候调用这个函数的实现.下面来看看它的实现步骤: 声明一个delegate对象. 实现和delegate具有相同 ...

  4. HDU 6200 2017沈阳网络赛 树上区间更新,求和

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6200 题意:给个图,有2种操作,一种是加一条无向边,二是查询u,v之间必须有的边的条数,所谓必须有的边 ...

  5. angularjs自定义指令实现分页插件

    由于最近的一个项目使用的是angularjs1.0的版本,涉及到分页查询数据的功能,后来自己就用自定义指令实现了该功能.现在单独做了个简易的小demo,主要是为了分享自己写的分页功能.注:本实例调用的 ...

  6. 换个角度审视NAT技术

    NAT (Network address translation,网络地址转换 )是局域网连接到互联网的一个对接工作. 首先要知道NAT是一个技术或者说软件而不是协议 后面你会知道NAT 是偏应用层但 ...

  7. JOptionPane弹框常用实例

    最近在做swing程序中遇到使用消息提示框的,JOptionPane类其中封装了很多的方法. 很方便的,于是就简单的整理了一下. 1.1 showMessageDialog 显示一个带有OK 按钮的模 ...

  8. [转载]浏览器事件window.onload、onfocus、onblur、ons

    原文地址:浏览器事件window.onload.onfocus.onblur.onscroll和resize作者:lilyxiao <html> <head> <titl ...

  9. jq分页插件,支持动态,静态分页的插件,简单易用。

    工作中经常要用到分页功能.为了方便封装了一个比较通用的分页插件开源出来了,简单易用. 官网:https://cwlch.github.io/Ch_Paging 下载地址:https://github. ...

  10. 【集美大学1411_助教博客】团队作业2——需求分析&原型设计 成绩

    首先要向各位同学道歉,最近助教的工作较多,并且伴随着频繁的出差,评论博客和评分都不及时,以致于同学们都没有得到反馈,在此我要表示歉意.其次,对于第二次团队作业,有两个团队没有提交到班级博客中但按时完成 ...