Zoj 1610 Count The Colors "Interval coverage for staining section"

Source: Internet
Author: User

Count the Colors Time limit: 2 Seconds Memory Limit: 65536 KB Painting some colored segments on a line, some previously painted segments could 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 all data set contains exactly one integer n, 1 <= n <= 8000, equal to the number of colored Segme Nts.

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 is in the range [0, 8000], and they is all integers.

Input may contain several data set, and process to the end of file.


Output

Each line of the output should contain a color index this can be seen from the top, following the count of the segments of This color, they should is printed according to the color index.

If some color can ' t is 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


Author: Standlove

Source: ZOJ Monthly, May 2003



Test Instructions: Dye a line of length 8000, and dye the interval [a, b] into a C color each time. Obviously, the color that is removed from the back will cover the previous color. after dyeing, each color has a number of intermittent intervals on the line segment.



Segment Tree lazy interval modified.


To my words, the output requirement is output by color numbering from 0 to 8000. And I foolishly output for 1 hours in the order of insertion ... O (╯-╰) o




AC Code:

#include <cstdio> #include <cstring> #include <algorithm> #define MAXN 8000+10using namespace Std;int color[maxn<<2];//to node staining void pushdown (int o) {if (Color[o]! =-1) {color[o<<1] = color[o<<1|1        ] = Color[o];    Color[o] =-1;        }}void Update (int o, int l, int r, int l, int r, int v) {if (L <= l && R >= R) {Color[o] = V;    return;    } pushdown (o);    int mid = (L + r) >> 1;    if (l <= mid) Update (O&LT;&LT;1, L, Mid, L, R, V); if (R > Mid) Update (o<<1|1, mid+1, R, L, R, v);} int rec[maxn];//Store i-node color int top = 0;void query (int o, int l, int r) {if (L = = r) {rec[top++] = color[o];//Record section    The color of the point return;    } int mid = (L + r) >> 1;    Pushdown (o);    Query (O<<1, L, mid); Query (o<<1|1, mid+1, R);}    int num[maxn];//record the number of segments the color appears int main () {int N;        while (scanf ("%d", &n)! = EOF) {memset (color,-1, sizeof (color)); Int A, B, C;            for (int i = 1; I <= N; i++) {scanf ("%d%d%d", &a, &b, &c);        Update (1, 1, 8000, a+1, B, c);//The corresponding color number is added one} memset (REC, 1, sizeof (REC));        top = 0;//Initialization of query (1, 1, 8000);        memset (num, 0, sizeof (num));//Initialize int i, J;        for (i = 0; i < top;)                {if (rec[i] = =-1) {i++;            Continue            } num[rec[i]]++;             for (j = i + 1; j < top; J + +) {if (rec[j]! = Rec[i] | | rec[j] = = 1) break;        } i = J;        } for (int i = 0; I <= 8000; i++) {if (Num[i]) printf ("%d%d\n", I, num[i]);    } printf ("\ n"); } return 0;}



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Zoj 1610 Count The Colors "Interval coverage for staining section"

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.