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. 建设一个能承受500万PV/每天的网站如果计算?

    PV是什么: PV是page view的简写.PV是指页面的访问次数,每打开或刷新一次页面,就算做一个pv. 计算模型: 每台服务器每秒处理请求的数量=((80%*总PV量)/(24小时*60分*60 ...

  2. Java多线程编程核心技术---Lock的基本概念和使用

    Lock接口: ReentrantLock的基本功能: ReentrantLock的lock和unlock方法进行加锁,解锁.可以起到和synchronized关键字一样的效果: 选择性通知!!!: ...

  3. 浅谈2015新版 U-Boot

    过了挺长一断时间没有看U-BOOT了,这两天下载了新版的UBOOT源码(之前看的一些书都是基于早好多年的源码来讲述,总感觉心里有点不对劲,也许是我比较喜新的原因吧,不过小弟我并没有厌旧哈),好了不多扯 ...

  4. 查看外网IP

    同一个网络,登录不同网站/APP, 显示的登录IP可能不一样. 输入ip138.com 得到外网IP: 输入:http://www.net.cn/static/customercare/yourip. ...

  5. spark版本不支持(降版本打包)

    在做项目的时候代码已经更新为hadoop 2.7  spark 2.1 scala 2.11.8版本,但是服务器版本使用的是hadoop2.6 spark1.6 以及scala2.10.6版本,,主程 ...

  6. ubuntu 12.04 配置iscsi共享及挂载iscsi共享

    一.配置ubuntu 下iscsi下的target 1.配置iscsi-target: sudo apt-get install iscsi* 2.配置一个简单的iscsi target: iscsi ...

  7. 【计算机网络】2.6 P2P应用

    第二章第六节 P2P应用 在本节内容开始前,我们要先来对P2P架构有一个宏观的认知: P2P:(Peer to Peer 对等结构)   以对等方式进行通信,并不区分客户端和服务端,而是平等关系进行通 ...

  8. 第2节 hive基本操作:12、hive当中的hql语法

    3.2. hive查询语法 3.2.1.SELECT https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Select 基本 ...

  9. 排序算法小结:C++实现

    #include<vector> #include<iostream> //排序算法的稳定性:对于相同的关键字,排序之前的位置和排序之后的位置相同,则称为稳定排序,否则不稳定排 ...

  10. buf.toJSON()

    buf.toJSON() 返回:{Object} 返回该 Buffer 实例的 JSON 表达式.当字符串化一个 Buffer 实例时会隐式调用 JSON.stringify() 这个函数. 例子: ...