Zoj1610--count the Colors

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

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


Line Tree of water problem


#include <map> #include <set> #include <list> #include <queue> #include <stack> #include <vector> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring># Include <iostream> #include <algorithm>using namespace std;const int N = 8010;int Cnt[n], ret;struct node{int l , R;int Col;} Tree[n << 2], Seg[n], rec[n];void build (int p, int l, int r) {tree[p].l = L;TREE[P].R = R;tree[p].col = -1;if (L = =) R) {return;} int mid = (L + R) >> 1;build (P << 1, L, mid); build (P << 1 | 1, mid + 1, r);} void Update (int p, int l, int r, int col) {if (TREE[P].L >= l && R >= tree[p].r) {tree[p].col = Col;return;} if (tree[p].col! =-1) {tree[p << 1].col = tree[p].col;tree[p << 1 | 1].col = Tree[p].col;tree[p].col =-1;} int mid = (tree[p].l + tree[p].r) >> 1;if (R <= mid) {Update (P << 1, L, R, col);} else if (L > Mid) {Update (P << 1 | 1, L, R, col);} Else{update (P << 1, L, Mid, Col); Update (P << 1 | 1, mid + 1, R, col);}} void query (int p) {if (Tree[p].col! =-1) {rec[ret].l = TREE[P].L;REC[RET].R = Tree[p].r;rec[ret++].col = Tree[p].col;retur n;} Query (P << 1); query (P << 1 | 1);} int main () {int n, L, R;while (~scanf ("%d", &n)) {L = 10000, r = -10000;memset (cnt, 0, sizeof (CNT)); for (int i = 0; I &l T N ++i) {scanf ("%d%d%d", &AMP;SEG[I].L, &AMP;SEG[I].R, &seg[i].col); l = min (l, seg[i].l); r = Max (r, SEG[I].R);} Build (1, L + 1, r), ret = 0;for (int i = 0; i < n; ++i) {update (1, SEG[I].L + 1, SEG[I].R, seg[i].col);} Query (1); cnt[rec[0].col]++;for (int i = 1; i < ret; ++i) {if (Rec[i].col! = rec[i-1].col) {cnt[rec[i].col]++;} else if (Rec[i].l > REC[I-1].R + 1) {cnt[rec[i].col]++;}} for (int i = 0; I <= 8000; ++i) {if (cnt[i]! = 0) {printf ("%d%d\n", I, Cnt[i]);}} printf ("\ n");} return 0;}


Zoj1610--count the Colors

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.