设为首页 加入收藏

TOP

ZOJ1610_Count the Colors(线段树/成段更新)
2015-07-20 17:57:04 来源: 作者: 【 】 浏览:6
Tags:ZOJ1610_Count the Colors 线段 成段 更新

解题报告

题意:

一根长度8000的线段上染色,求染完之后,每个颜色在线段上有多少个间断的区间。

思路:

区间问题用线段树,成段的更新区间,最后把所有的区间下压到叶子结点,统计叶子结点的颜色。

#include 
  
   
#include 
   
     #include 
    
      using namespace std; int lz[32000],_hash[10000],color[10000],cnt; void push_down(int rt) { if(lz[rt]) { lz[rt*2]=lz[rt*2+1]=lz[rt]; lz[rt]=0; } } void update(int rt,int l,int r,int ql,int qr,int v) { if(ql>r||qr
     
      附手动随机数据
      

input:
10
2 4 6 
4 6 2
1 9 3
4 6 2
1 20 3
2 4 3 
6 7 1
3 7 9
4 6 9
2 6 4
10
43 54 8000
323 4342 123
234 2332 321
2 6 23
54 546 1
2843 8888 8000
3000 8000 0
23 4329 9
923 2323 8
2390 3293 1
10
1 34 8000 
43 343 99
341 3414 8000
7999 8000 8000
344 345 1
434 3455 0
34 45 8000
43 56 45
56 64 0
898 4599 8000

output:
3 2
4 1
9 1

0 1
1 1
8 1
9 3
23 1

0 2
1 1
45 1
99 1
8000 5

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



】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇HDU2955Robberies 下一篇HUDJ 3270 The Diophantine Equat..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: