Problem
There is a grid $A$ consisting of $N$ rows and $M$ columns. The top left corner is denoted as $(1,1)$ and the bottom right corner is denoted as $(N,M)$. Initially, the grid is empty. There is also another array $B$ consisting of $K$ integers $B_1, B_2, \ldots, B_K$.
You are planning to fill the whole grid with the array $B$, starting from $B_1$. Each time when you fill in a number, you choose the unoccupied cell with the smallest row number to fill in. If two cells share the same row number, you choose the one with smaller column number.
For example, suppose $N=2$, $M=3$ and $B=[3,5,8,4,2,9]$. The filling process is as follows:
However, this is too easy. In order to increase the difficulty of the problem, the author adds a rule: After each insertion, if a number has appeared $\ge 2$ times inside the grid, then all of them will be deleted. The deleted cells will become empty, and can be filled in with numbers again in the future. We call this a deletion operation.
For example, suppose initially the grid contains $8$, $6$ and $5$, and $B=[8,5]$. The inserting process looks like this:
After inserting all elements inside $B$ into $A$ one by one, what is the resultant grid?
Input
The first line contains $3$ integers $N, M$ and $K$, denoting the dimensions of the grid and the size of $B$.
The second line contains $K$ integers $B_1, B_2, ... , B_K$, denoting the array $B$.
Output
Output $N \times M$ integers, denoting the resultant grid. For empty cells, output $0$.
Subtasks
For all test cases, $1 \le N, M \le 1000$, $1 \le K \le N \times M$, $1 \le B_i \le 10^9$ for $1 \le i \le K$
Subtask $1$ $(12$ pts$)$: $N=1$ and $B$ is pairwise distinct
Subtask $2$ $(15$ pts$)$: $B$ is pairwise distinct
Subtask $3$ $(31$ pts$)$: $K \le 5000$
Subtask $4$ $(29$ pts$)$: $B_i \le 10^6$ and it's guaranteed that the deletion operation will not be applied consecutively
Subtask $5$ $(13$ pts$)$: No Additional Constraints
Sample Test Cases
| Input | Output | |
|---|---|---|
| 1 5 5 5 4 3 2 1 |
5 4 3 2 1 | |
| This test case satisfies the special constraints of subtask 1. | ||
| 2 3 5 8 6 5 8 5 |
0 6 0 0 0 0 |
|
| This test case corresponds to the example shown in the problem statement. | ||
Scoring: Per Subtask
Authored by s22r42 and s22f26
Appeared in 2026 Mini Comp 3