G. Count the Colors

Time Limit: 2000ms
Memory Limit: 65536KB

64-bit integer IO format: %lld      Java class name: Main

 
 
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

 解题:线段树。。。比较奇葩的线段树,此树的叶子节点必须是一个长度为1的线段,而不是我通常所写的那种叶子节点就是一个点的那种。
 
[0,4]
[0,2][2,4]
[0,1][1,2][2,3][3,4]
是这种线段树。
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#define LL long long
#define INF 0x3f3f3f
using namespace std;
const int maxn = ;
struct node {
int lt,rt,color;
} tree[maxn<<];
int col[maxn],temp;
void build(int lt,int rt,int v) {
int mid = (lt+rt)>>;
tree[v].lt = lt;
tree[v].rt = rt;
tree[v].color = -;
if(lt+ == rt) return;
build(lt,mid,v<<);
build(mid,rt,v<<|);
}
void update(int lt,int rt,int c,int v) {
if(lt == rt || tree[v].color == c) return;
if(tree[v].lt >= lt && tree[v].rt <= rt) {
tree[v].color = c;
return;
}
if(tree[v].color >= ) {
tree[v<<].color = tree[v<<|].color = tree[v].color;
tree[v].color = -;
}
int mid = (tree[v].lt+tree[v].rt)>>;
if(rt <= mid) {
update(lt,rt,c,v<<);
} else if(lt >= mid) {
update(lt,rt,c,v<<|);
} else {
update(lt,mid,c,v<<);
update(mid,rt,c,v<<|);
}
tree[v].color = -;
}
void query(int v) {
if(tree[v].color == -) {
temp = -;
return;
}
if(tree[v].color != -) {
if(tree[v].color != temp) {
temp = tree[v].color;
col[temp]++;
}
return;
}
if(tree[v].lt+ != tree[v].rt) {
query(v<<);
query(v<<|);
}
}
int main() {
int n,i,j,x,y,c,mx;
while(~scanf("%d",&n)) {
build(,,);
memset(col,,sizeof(col));
mx = ;
for(i = ; i < n; i++) {
scanf("%d%d%d",&x,&y,&c);
update(x,y,c,);
if(c > mx) mx = c;
}
temp = -;
query();
for(i = ; i <= mx; i++)
if(col[i]) printf("%d %d\n",i,col[i]);
printf("\n");
}
return ;
}
 

xtu数据结构 G. 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

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

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

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

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

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

  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【题意+线段树区间更新&&单点查询】

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

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

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

随机推荐

  1. 【C#】.net 导出Excel功能

    将DataSet对象导出成Excel文档 一.不带格式控制 void btnExport_Click(object sender, EventArgs e) { IList<string> ...

  2. vuex2 10分钟快速入门

    因为太简单了,我直接就贴代码了~ #建立store.js import Vue from 'vue'; import Vuex from 'vuex'; Vue.use(Vuex) export de ...

  3. kafka安装和使用

    kafka安装和启动 kafka的背景知识已经讲了很多了,让我们现在开始实践吧,假设你现在没有Kafka和ZooKeeper环境. Step 1: 下载代码 下载0.10.0.0版本并且解压它. &g ...

  4. MongoDB自动递增序列

    MongoDB没有像SQL数据库外开箱即用自动递增功能.默认情况下,它采用了12字节的ObjectId为_id字段作为主键来唯一地标识文档.然而,可能存在的情况,我们可能希望_id字段有一些其它的自动 ...

  5. apache安装报错

    libtool: install: error: cannot install `libaprutil-1.la' to a directory not ending /some_directory ...

  6. Sublime Text 3 使用小记

    快捷键: [ // 代码对齐插件 { "keys": ["shift+alt+a"], "command": "alignment ...

  7. 浅析linux下软件的安装

    Linux环境: CentOs 6.0 知识点介绍: 一.tarball安装 安装步骤: 将tarball文件在/usr/local/src目录解压缩 ./configure:这个步骤是建立makef ...

  8. Mybatis配置多数据源

    一. Spring配置多数据源 二. Spring配置数据源 三. MultipleDataSource的实现 1: package com.wbl.modal; 2:  3: import org. ...

  9. lwz-过去一年的总结(15-16)

    今天2016年2月6日,还有1个半小时的时间,就要离开这个工作了9个月的地方,准备前往下个城市了.趁着这点时间,来给过去的一年做个即兴的总结吧. 2015年的2月份,在以前同学的提议和支持下,我重新学 ...

  10. QT 图形视图框架

    https://blog.csdn.net/qq769651718/article/details/79357936 使用QPushButton.QLabel.QCheckBox等构成GUI的控件或自 ...