程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> ZOJ1610_Count the Colors(線段樹/成段更新)

ZOJ1610_Count the Colors(線段樹/成段更新)

編輯:C++入門知識

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



  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved