Count the Colors

Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

Submit Status

Description

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

/*
题意:在数轴上用不同的颜色画线段,每一次画,可以覆盖上一次的颜色,问你所有操作完之后可以有多少种颜色,每种能看见的颜色的线段数 初步思路:线段树区间染色问题,实际上可以转化为一个区间set问题,每次操作就是进行一个染色 #错误:因为是闭区间,所以实际染色应该是[l,r);而且查询的时候不能在区间查询了,如果这样的话,在一个连续线段上的染色可能被记录两

*/
#include <bits/stdc++.h>
using namespace std;
/****************************线段树基础模板*********************************/
const int maxn=+; #define lson i*2, l, m
#define rson i*2+1, m+1, r
int color[maxn];//用来存放每种颜色的节点数的数组
int sum[maxn];
struct Segtree{ int setv[maxn<<];//记录以每个节点为根节点的线段的颜色 void PushDown(int i)
{
if(setv[i]!=-){
setv[i*]=setv[i*+]=setv[i];
setv[i]=-;
}
} void build(int i,int l,int r)
{
// cout<<l<<" "<<r<<endl;
setv[i]=-;//将每个节点都初始化为-1也就是什么颜色都没有
if(l==r)
return ;
int m=(l+r)>>;
build(lson);
build(rson);
}
void query(int ql,int qr,int i,int l,int r)
{
if(l==r){
sum[l]=setv[i];
return ;
}
PushDown(i);
int m=(l+r)>>;
if(ql<=m)query(ql,qr,lson);
if(m<qr)query(ql,qr,rson);
} void update(int ql,int qr,int val,int i,int l,int r)
{
if(ql<=l&&r<=qr)
{
setv[i]=val;//更新这个节点的值
return ;
}
PushDown(i);//先向下更新
int m=(l+r)>>;
if(ql<=m) update(ql,qr,val,lson);
if(m<qr) update(ql,qr,val,rson);
}
};
Segtree segtree;
/****************************线段树基础模板*********************************/
int l,r,c;
int n;
void init(){
memset(color,,sizeof color);
memset(sum,-,sizeof sum);
}
int main(){
// freopen("in.txt","r",stdin);
while(scanf("%d",&n)!=EOF){
init();
segtree.build(,,maxn-);
for(int i=;i<n;i++){
scanf("%d%d%d",&l,&r,&c);
segtree.update(l+,r,c,,,maxn-);
}
segtree.query(,maxn-,,,maxn-);
// for(int i=0;i<=4;i++){
// cout<<sum[i]<<" ";
// }cout<<endl;
for(int i=;i<maxn;i++){
while(i!=&&sum[i]!=-&&sum[i]==sum[i-])//跑完连续的区间
i++;
color[sum[i]]++;
}
for(int i=;i<maxn;i++){
if(color[i]>){
printf("%d %d\n",i,color[i]);
}
}
printf("\n");
}
return ;
}

Count the Colors的更多相关文章

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

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

  2. zoj 1610 Count the Colors

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=610  Count the Colors Time Limit:2000MS   ...

  3. Count the Colors(线段树,找颜色段条数)

    Count the Colors Time Limit: 2 Seconds      Memory Limit: 65536 KB Painting some colored segments on ...

  4. (线段树) Count the Colors --ZOJ --1610

    链接: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82832#problem/F http://acm.zju.edu.cn/onli ...

  5. zoj 1610 Count the Colors 线段树区间更新/暴力

    Count the Colors Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/show ...

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

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

  7. ZOJ 1610 Count the Colors【题意+线段树区间更新&&单点查询】

    任意门:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1610 Count the Colors Time Limit: 2 ...

  8. xtu数据结构 G. Count the Colors

    G. Count the Colors Time Limit: 2000ms Memory Limit: 65536KB 64-bit integer IO format: %lld      Jav ...

  9. zoj 1610 Count the Colors 【区间覆盖 求染色段】

    Count the Colors Time Limit: 2 Seconds      Memory Limit: 65536 KB Painting some colored segments on ...

随机推荐

  1. OpenStack Pike超详细搭建文档 LinuxBridge版

    前言 搭建前必须看我 本文档搭建的是分布式P版openstack(1 controller + N compute + 1 cinder)的文档. openstack版本为Pike. 搭建的时候,请严 ...

  2. angular学习笔记02 angular指令大全

    第一步 先要引入angular, 第二步  在 html 标签中<html  ng-app>  加入ng-app(这是个必须的,不然会报错) 接下来就可以去使用angular的各种指令了. ...

  3. oracle 权限

    一.介绍这一部分我们主要看看oracle中如何管理权限和角色,权限和角色的区别在哪里.当刚刚建立用户时,用户没有任何权限,也不能执行任何操作.如果要执行某种特定的数据库操作,则必须为其授予系统的权限: ...

  4. hibernate学习手记(1)

    1. java.sql.SQLException: The server time zone value '?й???????' is unrecognized or represents more ...

  5. 我的three.js学习记录(一)

    在之前因为项目需要使用WebGL技术做网页应用,但是苦于自己没有接触,只是使用过OpenGL.然后接触到了thre.js这个第三方库之后我突然心情很愉快,这将节省我很多时间. 过了这个项目之后,就再也 ...

  6. PHP,Mysql根据经纬度计算距离并排序

    网上给出的计算公式是这样的: Lng1表示A点纬度和经度,Lat2 Lng2 表示B点纬度和经度 a = Lat1 – Lat2为两点纬度之差 b = Lng1 -Lng2 为两点经度之差 6378. ...

  7. VTL(Velocity Templates Language,即Velocity模板语言)初识语法总结

    1.velocity是一门基于Java语言的视图表现层模板引擎,它可以取代jsp,比jsp更高效. 2.velocity变量的定义与引用 (1).定义一个变量:#set ($a = "vel ...

  8. js 防止变量冲突

    解决方法 sc1 和sc2 的a都是window.a 会指向一个变量 1:使用匿名函数将脚本包起来,全局变量用来通信 如window.x; 2:命名空间 代码: <script> (fun ...

  9. 从零开始配置TypeScript + React + React-Router + Redux + Webpack开发环境

    转载请注明出处! 说在前面的话: 1.为什么不使用现成的脚手架?脚手架配置的东西太多太重了,一股脑全塞给你,我只想先用一些我能懂的库和插件,然后慢慢的添加其他的.而且自己从零开始配置也能学到更多的东西 ...

  10. javascript Dom 编程

     javascript Dom  编程 知识概要: (1)Dom是什么? (2)Dom结构模型 (3)XML DOM和 HTML DOM (4)NODE接口的特性和方法 (5)DOM结点的常用属性 ...