atcoder#ARC130B. [ARC130B] Colorful Lines

[ARC130B] Colorful Lines

Score : 400400 points

Problem Statement

We have an H×WH\times W grid. Initially, the squares are unpainted.

You will paint these squares. There are CC colors available, numbered 1,2,,C1, 2, \ldots, C.

The painting process will be given as QQ queries. The ii-th query contains integers ti,ni,cit_i, n_i, c_i, which represents the following action.

  • If ti=1t_i = 1: paint all squares in the nin_i-th row with Color cic_i.
  • If ti=2t_i = 2: paint all squares in the nin_i-th column with Color cic_i.

Painting a square with Color cc makes the color of that square Color cc, regardless of its previous state.

Find the number of squares painted in each of Color 1,2,,C1, 2, \ldots, C after the whole process.

Constraints

  • 2H1092\leq H\leq 10^9
  • 2W1092\leq W\leq 10^9
  • 1C3×1051\leq C\leq 3\times 10^5
  • 1Q3×1051\leq Q\leq 3\times 10^5
  • ti{1,2}t_i\in \{1,2\}
  • 1niH1\leq n_i\leq H if ti=1t_i = 1
  • 1niW1\leq n_i\leq W if ti=2t_i = 2
  • 1ciC1\leq c_i\leq C

Input

Input is given from Standard Input in the following format:

HH WW CC QQ

t1t_1 n1n_1 c1c_1

\vdots

tQt_Q nQn_Q cQc_Q

Output

Print a line containing the numbers of squares painted in Color 1,2,,C1, 2, \ldots, C, 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