atcoder#ARC130B. [ARC130B] Colorful Lines
[ARC130B] Colorful Lines
Score : points
Problem Statement
We have an grid. Initially, the squares are unpainted.
You will paint these squares. There are colors available, numbered .
The painting process will be given as queries. The -th query contains integers , which represents the following action.
- If : paint all squares in the -th row with Color .
- If : paint all squares in the -th column with Color .
Painting a square with Color makes the color of that square Color , regardless of its previous state.
Find the number of squares painted in each of Color after the whole process.
Constraints
- if
- if
Input
Input is given from Standard Input in the following format:
Output
Print a line containing the numbers of squares painted in Color , with spaces in between.
4 5 6 5
1 1 6
1 3 3
2 2 4
2 4 2
1 1 2
0 8 3 3 0 0
The process changes the colors of the squares as follows. Here, .
denotes an unpainted square.
..... 66666 66666 64666 64626 22222
..... ..... ..... .4... .4.2. .4.2.
..... ..... 33333 34333 34323 34323
..... ..... ..... .4... .4.2. .4.2.
1000000000 1000000000 3 5
1 1 2
1 2 2
1 3 2
1 4 2
1 5 2
0 5000000000 0