题目链接: 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. 【iOS】Updating local specs repositories

    使用 Pods 时遇到这个问题,原因是被墙了……需换成下面命令: pod install --verbose --no-repo-update

  2. ansible-service

    #service#查询服务状态 ansible server01 -m service -a "name=httpd state=started" #停止服务 ansible se ...

  3. input属性设置type="number"之后, 仍可输入e, E, -, + 的解决办法

    <el-input v-model="scope.row.variables.leaderbuweiscores.score" @keyup.native="cha ...

  4. 什么?小程序实时语音识别你还在痛苦的对接科大讯飞?百度Ai识别?

    前言 微信小程序,说不上大火,但是需求还是不少的.各大企业都想插一足 于是前端同学就有事情做了. 需求 我需要录音 我边说话边识别,我要同声传译,我要文字转语音,还要萝莉音 我:??? 正文 一开始, ...

  5. 图解Redis之数据结构篇——压缩列表

    前言     同整数集合一样压缩列表也不是基础数据结构,而是 Redis 自己设计的一种数据存储结构.它有点儿类似数组,通过一片连续的内存空间,来存储数据.不过,它跟数组不同的一点是,它允许存储的数据 ...

  6. 记录eclipse中文出现空格宽度不一致的bug

    起因 不久前更新了 eclipse(2019-03) 版本:突然发现出现了,使用注释使用中出现的空格的间隔大小不一致的问题,具体可以看下图: 遇到这种问题简直逼不能忍,在网上搜一下解决方式: 谷歌 搜 ...

  7. 第十章 Centos7-系统进程管理 随堂笔记

    第十章 Centos7-系统进程管理 本节所讲内容: 10.1 进程概述和ps查看进程工具 10.2 uptime查看系统负载-top动态管理进程 10.3 前后台进程切换- nice进程优先级-实战 ...

  8. @Value注解 和 @Data注解

    @Value注解 service层代码 @Service public class HelloServiceImpl implements HelloService { @Autowired priv ...

  9. macos Mojave 出现网络出错 Frame Check Sequence: Bad checksum

    问题描述:使用软电话外呼的时候出现Request Timeout . 端口监听之后通过 Wireshark发现错误:`Frame Check Sequence: Bad checksum`,查看wir ...

  10. ABAP:如何等待小数秒数

    WAIT UP TO x SECONDS. 和CALL FUNCTION 'ENQUE_SLEEP'都只能支持整数的秒数(如果是非整数,则四舍五入),如果要WAIT非整数的描述,可以如下写法: