题目链接: 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. Thymeleaf 模板 springboot集成使用

    一.Thymeleaf是什么? 简单说, Thymeleaf 是一款用于渲染XML/XHTML/HTML5内容的模板引擎,类似我之前用过的FreeMarker .由于它支持 html 原型,然后在 h ...

  2. poj 3253 Fence Repair(优先队列+huffman树)

    一个很长的英文背景,其他不说了,就是告诉你锯一个长度为多少的木板就要花多少的零钱,把一块足够长(不是无限长)的木板锯成n段,每段长度都告诉你了,让你求最小花费. 明显的huffman树,优先队列是个很 ...

  3. spring boot 学习笔记之前言----环境搭建(如何用Eclipse配置Maven和Spring Boot)

    本篇文档来源:https://blog.csdn.net/a565649077/article/details/81042742 1.1 Eclipse准备 (1)     服务器上安装JDK和Mav ...

  4. Java 获取操作系统相关的内容

    package com.hikvision.discsetup.util; import java.lang.reflect.Field; import java.net.InetAddress; i ...

  5. 使用用树莓派打造远程WEB服务器

    简介:系统配置Raspberry Pi 3B + Raspbian + MySQL5.7 + Tomcat 9 + Nginx + 公网IP. 工具:Win32DiskImager .FileZill ...

  6. 学习vue感触

    大学还没毕业,想着先找工作,感觉计算机专业在老家做没有太大的发展,于是就在大学所在城市找了份工作.来到公司的第一天,带我的师傅让我学习vue.之前完全没有接触过框架,而且专业知识比较薄弱,前几天一直处 ...

  7. 【Java例题】5.3 线性表的使用

    3.线性表的使用.使用ArrayList模拟一个一维整数数组.数据由Random类随机产生.进行对输入的一个整数进行顺序查找.并进行冒泡排序. package chapter6; import jav ...

  8. Spring Boot 修改静态资源一定要重启项目才会生效吗?未必!

    回顾热部署 Spring Boot 中的热部署相信大家都用过吧,只需要添加 spring-boot-devtools 依赖就可以轻松实现热部署.Spring Boot 中热部署最最关键的原理就是两个不 ...

  9. HTML/CSS:图片居中(水平居中和垂直居中)

    css图片居中(水平居中和垂直居中) css图片居中分css图片水平居中和垂直居中两种情况,有时候还需要图片同时水平垂直居中, 下面分几种居中情况分别介绍: css图片水平居中 1.利用margin: ...

  10. Element-UI 表单验证规则rules 配置参数说明

    官方文档 : https://github.com/yiminghe/async-validator