题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1610

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

在[0, 8000]涂色,后涂的会覆盖前面涂的,求每种颜色最后能分辨的的区块有多少个。

建树时,树的单位是区间,而不是点 如[0, 8000]的左右儿子应该分别是[0, 4000], [4000,8000];

询问时,需要判断相邻区间的颜色是否相同 用temp记录前一区间所记录的颜色来解决这个问题。

 #include<iostream>
#include<cstring>
using namespace std; int color[];
int mark[];
int temp; void Build( int i, int l, int r ){
mark[i] = -;//-1表示没有涂 if( l + == r ) return; int mid = ( l + r ) >> ;
Build( i << , l , mid );
Build( ( i << ) | , mid, r );
} void Insert( int i, int l, int r, int z, int y, int c ){
if( l == r ) return;
if( z <= l && y >= r ){
mark[i] = c;
return;
}
if( mark[i] == c ) return;
if( mark[i] >= ){
mark[i << ] = mark[i];
mark[( i << ) | ] = mark[i];
mark[i] = -;//该区间含有多个颜色
}
int mid = ( l + r ) >> ;
if( y <= mid ) Insert( i << , l, mid, z, y, c );
else if( z >= mid ) Insert( ( i << ) | , mid, r, z, y, c );
else{
Insert( i << , l, mid, z, mid, c );
Insert( ( i << ) | , mid, r, mid, y, c );
}
mark[i] = -;
} void Queue( int i, int l, int r){
if( mark[i] == - ){
temp = -;
return;
}
if( mark[i] >= ){
if( temp != mark[i] ){
temp = mark[i];//记录前一段的颜色
color[mark[i]]++;
}
return;
}
if( l + != r ){
int mid = ( l + r ) >> ;
Queue( i << , l, mid );
Queue( ( i << ) | , mid, r );
}
} int main(){
ios::sync_with_stdio( false ); int n;
while( cin >> n ){ Build( , , );
memset( color, , sizeof( color ) ); int a, b, c, max = ;
for( int i = ; i <= n; i++ ){
cin >> a >> b >> c;
Insert( , , , a, b, c );
max = c > max ? c : max;
} temp = -;
Queue( , , ); for( int i = ; i <= max ; i++ )
if( color[i] ) cout << i << " " << color[i] << endl; cout << endl;
} return ;
}

ZOJ-1610 Count the Colors ( 线段树 )的更多相关文章

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

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

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

    题意 : 给出 n 个染色操作,问你到最后区间上能看见的各个颜色所拥有的区间块有多少个 分析 : 使用线段树成段更新然后再暴力查询总区间的颜色信息即可,这里需要注意的是给区间染色,而不是给点染色,所以 ...

  3. ZOJ 1610 Count the Colors(线段树,区间覆盖,单点查询)

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

  4. ZOJ 1610 Count the Color(线段树区间更新)

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

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

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

  6. ZOJ 1610.Count the Colors-线段树(区间染色、区间更新、单点查询)-有点小坑(染色片段)

    ZOJ Problem Set - 1610 Count the Colors Time Limit: 2 Seconds      Memory Limit: 65536 KB Painting s ...

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

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

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

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

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

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

  10. zoj 1610 Count the Colors(线段树延迟更新)

    所谓的懒操作模板题. 学好acm,英语很重要.做题的时候看不明白题目的意思,我还拉着队友一块儿帮忙分析题意.最后确定了是线段树延迟更新果题.我就欣欣然上手敲了出来. 然后是漫长的段错误.... 第一次 ...

随机推荐

  1. 新浪微博SSO授权后回调客户端没有执行sinaweiboDidLogIn&无法返回应用

    TARGETS --> URL Types --> 添加  --> 在URL Schemes里填上sinaweibosso.XXXX(AppKey),Identifier这里可以随机 ...

  2. java中对事务的理解

    一.什么是事务 事务是访问数据库的一个操作序列,数据库应用系统通过事务集来完成对数据库的存取. 二.事务的原则(ACID) 原子性:事务要么全部都被执行,要么就全都不被执行,如果有子事务提交失败,那么 ...

  3. C# 10分钟完成百度语音技术(语音识别与合成)——入门篇

    我们已经讲了人脸识别(入门+进阶).图片识别(入门).下面是链接: C# 10分钟完成百度人脸识别——入门篇 C# 30分钟完成百度人脸识别——进阶篇(文末附源码) C# 10分钟完成百度图片提取文字 ...

  4. 【Java例题】7.4 文件题1-学生成绩排序

    4.学生成绩排序.已有一个学生成绩文件,含有多位学生的成绩:读取这个文件中的每位学生的成绩,然后排序:最后将这些排好序的成绩写到另一个文件中. package chapter7; import jav ...

  5. iOS的录屏功能

    iOS的录屏功能其实没什么好说的,因为网上的教程很多,但是网上的Demo无一例外几乎都有一个bug,那就是iPad上会出现闪退,这也体现了国内的教程文档的一个特点,就是抄袭,教程几乎千篇一律,bug也 ...

  6. 一个web前端开发者的日常唠叨

    时间飞逝,距离上一次更新博客已经过去了三个月,上一篇博客的发布时间停留在了4月4日. 近来三个月没有更新博客,深感抱歉和愧疚.停更博客就意味着学习的越来越少,作为一个普通的前端开发者来说这是万万不可取 ...

  7. c# 三步递交模式调用同一个存储过程

    主要用于批量的sql操作:第一步创建中间表,第二步多次写数据到中间表,第三步 提交执行 创建三步递交的存储过程: CREATE PROC usp_testsbdj@bz int=0,@name VAR ...

  8. 记一次mysql数据库失而复得过程

    背景: 由于是自己买的vps搭建的博客,用的是军哥的一键lnmp源码编译安装的,文章也就几篇,对备份并不太重视,想着等服务器快到期的时候备份一下不就行了. 后来在该服务器上测试lnmp分别编译编译安装 ...

  9. opencv 视觉项目学习笔记(二): 基于 svm 和 knn 车牌识别

    车牌识别的属于常见的 模式识别 ,其基本流程为下面三个步骤: 1) 分割: 检测并检测图像中感兴趣区域: 2)特征提取: 对字符图像集中的每个部分进行提取: 3)分类: 判断图像快是不是车牌或者 每个 ...

  10. Appium+python自动化(三十三)- 环境(超详解)

    简介 在前边所有涉及启动app的时候有这样一行代码driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps),很多小 ...