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.

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.

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

题目大意:

在一条线上花颜色,求出最后看到的颜色种类

分析:

因为从0开始,所以应该用区间

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<stdlib.h>
using namespace std;
#define N 8005
#define Lson r<<1
#define Rson r<<1|1
int sum[N],temp; struct node
{
int L,R,e;
int mid()
{
return (L+R)/;
}
int len()
{
return R-L+;
}
}a[N*]; void BuildTree(int r,int L,int R)
{
a[r].L=L;
a[r].R=R;
a[r].e=-;
if(L==R-)
{
return;
}
BuildTree(Lson,L,a[r].mid());
BuildTree(Rson,a[r].mid(),R);
}
void Qurry(int r)
{
if(a[r].e!=-)
{
if(a[r].e!=temp)
{//temp表示这个区间的颜色没有被加过
sum[a[r].e]++;
}
temp=a[r].e;
return;
}
if(a[r].L==a[r].R-)
{
temp=-;
return;
}
Qurry(Lson);
Qurry(Rson);
}
void Update(int r,int L,int R,int e)
{ if(a[r].L==L && a[r].R==R)
{
a[r].e=e;
return;
}
if(a[r].e!=-)
{
a[Lson].e=a[Rson].e=a[r].e;
a[r].e=-;
}
if(R<=a[r].mid())
Update(Lson,L,R,e);
else if(L>=a[r].mid())
Update(Rson,L,R,e);
else
{
Update(Lson,L,a[r].mid(),e);
Update(Rson,a[r].mid(),R,e);
}
}
int main()
{
int n,x,y,e;
while(scanf("%d",&n)!=EOF)
{
memset(sum,,sizeof(sum));
BuildTree(,,N);
int Max=;
for(int i=;i<n;i++)
{
scanf("%d %d %d",&x,&y,&e);
Max=max(Max,e);
Update(,x,y,e); }
temp=-;
Qurry();
for(int i=;i<=Max;i++)
{
if(sum[i])
{
printf("%d %d\n",i,sum[i]);
}
}
printf("\n");
}
return ;
}

Count the Colors-ZOJ1610(线段树区间求)的更多相关文章

  1. ZOJ - 1610 Count the Colors(线段树区间更新,单点查询)

    1.给了每条线段的颜色,存在颜色覆盖,求表面上能够看到的颜色种类以及每种颜色的段数. 2.线段树区间更新,单点查询. 但是有点细节,比如: 输入: 2 0 1 1 2 3 1 输出: 1 2 这种情况 ...

  2. ZOJ 1610 Count the Colors (线段树区间更新)

    题目链接 题意 : 一根木棍,长8000,然后分别在不同的区间涂上不同的颜色,问你最后能够看到多少颜色,然后每个颜色有多少段,颜色大小从头到尾输出. 思路 :线段树区间更新一下,然后标记一下,最后从头 ...

  3. ZOJ 1610——Count the Colors——————【线段树区间替换、求不同颜色区间段数】

    Count the Colors Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Subm ...

  4. ZOJ 1610 Count the Colors (线段树区间更新与统计)

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

  5. Zoj 1610 Count the Colors (线段树+区间更新+暴力计数)

    题目大意: 有n次操作,每次都是对一根线中的一段区间进行染色(颜色并不相同),有时候后面的颜色有可能覆盖前面的颜色,问最后涂完色,能看到的颜色有几种,每种颜色有几部分? 解题思路: 这个题目建树的时候 ...

  6. ZOJ - 1610 Count the Colors(线段树区间更新)

    https://cn.vjudge.net/problem/ZOJ-1610 题意 给一个n,代表n次操作,接下来每次操作表示把[l,r]区间的线段涂成k的颜色其中,l,r,k的范围都是0到8000. ...

  7. hdu4521-小明系列问题——小明序列(线段树区间求最值)

    题意:求最长上升序列的长度(LIS),但是要求相邻的两个数距离至少为d,数据范围较大,普通dp肯定TLE.线段树搞之就可以了,或者优化后的nlogn的dp. 代码为  线段树解法. #include ...

  8. hdu 1754 I Hate It(线段树区间求最值)

    I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  9. Count the Colors(线段树染色)

    Count the Colors Time Limit:2000MS    Memory Limit:65536KB    64bit IO Format:%lld & %llu Submit ...

  10. F - Count the Colors(线段树)

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

随机推荐

  1. 在阿里云上搭建nginx + ThinkPHP 的实践

    作为一个程序猿,理应用linux系统来作为平时的工作机环境,哎,之前倒是用过一段时间的linux,可惜后来换了本本,后来竟然没有保持,嗷嗷后悔中... 废话不多说,大家用windows的理由都一样,但 ...

  2. 正则表达式 - IP地址、Mac地址、端口、经纬度、车牌号码校验

    IP地址验证:   /^(\d|[1-9]\d|1\d{2}|2[0-5][0-5])\.(\d|[1-9]\d|1\d{2}|2[0-5][0-5])\.(\d|[1-9]\d|1\d{2}|2[0 ...

  3. [eclipse]的快捷键的设置

    今天新解压了一个eclipse,发现alt+/提示的快捷键不好用了,开始比较犯懒,但是发现开发效率低下,总结几个eclipse下快捷方式的解决办法. 第一个解决没有一点提示的情况. 1.首先通过菜单打 ...

  4. clusterdb - 对一个PostgreSQL数据库进行建簇

    SYNOPSIS clusterdb [ connection-option...] [ --table | -t table] [ dbname] clusterdb [ connection-op ...

  5. bash之数组

    Bash 提供索引和联想的一维数组变量.可用作任何变量 索引的数组 :内置的声明将显式声明数组.有没有最大限制 一个数组,也没有要求成员将索引或连续分配的大小.索引的数组 引用使用 (包括算术表达式) ...

  6. Hadoop推测执行机制问题

    问题描述:MultipleOutputs使用时hdfs报错         // :: INFO mapreduce.Job: Task Id : attempt_1525336138932_1106 ...

  7. flutter 上传图片 image_picker 的使用

    Github地址: https://github.com/flutter/plugins/tree/master/packages/image_picker packages地址: https://p ...

  8. docker centos7 配置和宿主机同网段IP

    docker centos7 配置和宿主机同网段IP 1.安装brctl 命令 # yum -y install bridge-utils 2.编辑网卡配置文件 # vi ifcfg-eno16777 ...

  9. show()的几种方法

    1 show()方法和hide()方法 $("selector").show()  从display:none还原元素默认或已设置的display属性$("selecto ...

  10. vue-router scrollBehavior的用法

    问题: 使用keep-alive标签后部分安卓机返回缓存页位置不精确问题 解决方案: <div id="app"> <keep-alive> <rou ...