ZOJ1610_Count the Colors (line segment tree/segment update)

Source: Internet
Author: User

ZOJ1610_Count the Colors (line segment tree/segment update)

Solution report

Question:

A 8000-length line segment is colored to determine the number of consecutive intervals in each color segment after dyeing.

Ideas:

For the interval problem, we use a line segment tree to update the segments. At last, we press all the segments to the leaf node to calculate the color of the leaf node.

# 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
    
     
Attached manual random data
     

input:102 4 6 4 6 21 9 34 6 21 20 32 4 3 6 7 13 7 94 6 92 6 41043 54 8000323 4342 123234 2332 3212 6 2354 546 12843 8888 80003000 8000 023 4329 9923 2323 82390 3293 1101 34 8000 43 343 99341 3414 80007999 8000 8000344 345 1434 3455 034 45 800043 56 4556 64 0898 4599 8000output:3 24 19 10 11 18 19 323 10 21 145 199 18000 5

Count the Colors Time Limit: 2 Seconds Memory Limit: 65536 KB Painting some colored segments on a line, some previusly painted segments may be covered by some of 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 shoshould contain a color index that can be seen from the top, following the count of the segments of this color, they shocould 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



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.