問題一覧 > 通常問題

No.606 Colorful Tiles

レベル : / AI推定難易度 : 850 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 120
作問者 : FF256grhy / テスター : はむこ
お気に入りにしたユーザー ProblemId : 2011 / 自分の提出
問題文最終更新日: 2026-06-26 20:42:22
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
Advent Calendar Contest 2017 (順位表) の他の問題:

Problem Statement

We will paint $N^2$ tiles arranged in $N$ rows and $N$ columns. There are $K$ colors, numbered from $1$ to $K$, and initially all tiles are painted in color $1$. A total of $Q$ painting operations are performed. In the $i$-th operation, if $A_i$ is "R", all tiles in row $B_i$ are repainted, and if it is "C", all tiles in column $B_i$ are repainted, with color $C_i$. Find how many tiles of each color there are in the end.

Input

$N$ $K$ $Q$
$A_1$ $B_1$ $C_1$
$\vdots$
$A_Q$ $B_Q$ $C_Q$

All input values except $A_i$ ($1 \leq i \leq Q$) are integers, and the input satisfies the following constraints.
$1 \leq N \leq 10^5$
$1 \leq K \leq 10^5$
$1 \leq Q \leq 10^5$
$A_i$ is "R" or "C" ($1 \leq i \leq Q$)
$1 \leq B_i \leq N$ ($1 \leq i \leq Q$)
$1 \leq C_i \leq K$ ($1 \leq i \leq Q$)

Output

On line $i$, print the number of tiles that end up in color $i$ ($1 \leq i \leq K$). Print a newline at the end of every line, including the last line.

Sample

Sample 1
Input
3 4 6
C 1 2
C 2 3
R 2 1
C 3 4
R 3 3
C 2 1
Output
4
1
2
2

The tiles are painted as follows.

Sample 2
Input
1 5 2
R 1 4
R 1 4
Output
0
0
0
1
0

Some colors may never be used.

Sample 3
Input
100000 2 1
R 12345 2
Output
9999900000
100000

Note that the answer may not fit in a 32 bit integer type.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。