Count the Colors


Time Limit: 2 Seconds      Memory Limit: 65536 KB

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

用col[rt]记录区间的颜色,-1表示多个颜色。。。

#include <bits/stdc++.h>
using namespace std;
#define root 1,n,1
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define lr rt<<1
#define rr rt<<1|1
const int N = ;
int n , m , col[N<<],tag[N<<] ; void Down( int l , int r , int rt ) {
if( col[rt] != - ) col[lr] = col[rr] = col[rt] ;
}
void Up( int rt ){
if( col[lr] == col[rr] ) col[rt] = col[lr];
else col[rt] = - ;
}
void build( int l , int r , int rt ){
col[rt] = - ;
if( l == r ) return ;
int mid = (l+r)>>;
build(lson),build(rson);
}
void update( int l , int r , int rt , int L , int R , int c ) {
if( L == l && r == R ) {
col[rt] = c ; return ;
}
if( col[rt] == c ) return ;
else Down( l,r,rt ) , col[rt] = - ;
int mid = (l+r)>>;
if( R <= mid ) update(lson,L,R,c);
else if( L > mid ) update(rson,L,R,c);
else update(lson,L,mid,c) , update(rson,mid+,R,c);
Up(rt);
} int query( int l , int r , int rt , int x ) {
if( col[rt] != - || l == r ) return col[rt];
Down(l,r,rt);
int mid = (l+r)>>;
if( x <= mid ) return query(lson,x);
else return query(rson,x);
} int main()
{
int _ ,x ,y , c ;
n = ;
while( ~scanf("%d",&m) ) {
memset( tag , , sizeof tag );
build(root);
while( m-- ) {
scanf("%d%d%d",&x,&y,&c);x++;
update(root,x,y,c);
}
int last = - , now ;
for( int i = ; i <= n ; ++i ) {
now = query(root,i);
if( last == - ) { last = now ; continue ; }
if( last == now ) continue ;
else tag[last]++; last=now;
}
for( int i = ; i <= n ; ++i ) if( tag[i] ){
printf("%d %d\n",i,tag[i]);
}printf("\n");
}
}

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 Color(线段树区间更新)

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

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

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

  4. POJ 2528 Mayor's posters(线段树,区间覆盖,单点查询)

    Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 45703   Accepted: 13239 ...

  5. 【POJ 2777】 Count Color(线段树区间更新与查询)

    [POJ 2777] Count Color(线段树区间更新与查询) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4094 ...

  6. HDU.1556 Color the ball (线段树 区间更新 单点查询)

    HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...

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

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

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

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

  9. HDU 5861 Road 线段树区间更新单点查询

    题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5861 Road Time Limit: 12000/6000 MS (Java/Othe ...

随机推荐

  1. JavaScript 的执行机制

    一.关于javascript javascript是一门单线程语言,在最新的HTML5中提出了Web Worker,但javascript是单线程这一核心仍未改变. 为什么js是单线程的语言?因为最初 ...

  2. layui在当前页面弹出一个iframe层,并改变这个iframe层里的一些内容

    layer.open({ type: 2, title: "专家信息", area: ['100%', '100%'], content: '/ZhuanJiaKu/AddZhua ...

  3. 【转载】JDK8 特性 stream(),lambda表达式,

    Stream()表达式 虽然大部分情况下stream是容器调用Collection.stream()方法得到的,但stream和collections有以下不同: 无存储.stream不是一种数据结构 ...

  4. 372-基于XC7VX690T的高速模拟信号、万兆光纤综合计算平台

    基于XC7VX690T的高速模拟信号.万兆光纤综合计算平台 一.板卡概述 基于V7的高性能PCIe信号处理板,板卡选用Xilinx 公司Virtex7系列FPGA XC7VX690T-2FFG1761 ...

  5. 洛谷P3158 [CQOI2011]放棋子 组合数学+DP

    题意:在一个m行n列的棋盘里放一些彩色的棋子,使得每个格子最多放一个棋子,且不同颜色的棋子不能在同一行或者同一列.有多少祌方法? 解法:这道题不会做,太菜了qwq.题解是看洛谷大佬的. 设C是组合数, ...

  6. Java反编译工具Luyten-0.5.3

    Luyten是一款很强大的反编译工具包,是一款github的开源工具,软件功能非常强大,界面简洁明晰.操作方便快捷,设计得很人性化. 工具软件下载路径:https://github.com/death ...

  7. java四种引用类型以及使用场景详解

    每种编程语言都有自己操作内存中元素的方式,例如在 C 和 C++ 里是通过指针,而在 Java 中则是通过“引用”.在 Java 中一切都被视为了对象,但是我们操作的标识符实际上是对象的一个引用(re ...

  8. C++数组读入MATLAB数据

    data = rand(8, 10); fid = fopen('File.data', 'w'); if fid == - 1 error('Cannot open file for writing ...

  9. [转]php判断mysql_query是否成功执行

    针对update 语句等会对数据表进行修改的语句 在mysql_query($sql);后面加上 $result = mysql_affected_rows(); 如果$result 值为-1表明语句 ...

  10. 选项卡jq

    1.无定时器 $(function(){$('.banner-point li').on('click',function(){$(this).addClass('active').siblings( ...