#K56507. Arrange Books on a Bookshelf

    ID: 30213 Type: Default 1000ms 256MiB

Arrange Books on a Bookshelf

Arrange Books on a Bookshelf

You are given a bookshelf with n slots, initially all empty. The shelf is represented as an array of n integers with each empty slot denoted by -1.

You must perform m operations on the bookshelf. Each operation is represented by a triplet (op, i, j) where:

  • If op = 1, and slot i is empty, insert the book with identifier j into slot i (1-indexed). If the slot is already occupied, the operation is ignored.
  • If op = 0, remove the book from slot i if it is not empty. The value of j is ignored in this case.

After all operations, output the final state of the bookshelf. Formally, if the bookshelf is denoted as an array \(A = [a_1, a_2, \dots, a_n]\), then initially \(a_k = -1\) for \(1 \le k \le n\). For an insertion operation, if \(a_i = -1\), set \(a_i = j\). For a removal operation, if \(a_i \neq -1\), set \(a_i = -1\).

Note: The input will be given using standard input (stdin) and the output should be printed to standard output (stdout).

inputFormat

The first line of input contains two integers n and m, representing the number of slots on the bookshelf and the number of operations, respectively.

The next m lines each contain three integers: op, i, and j. Here, op indicates the type of operation, where 1 is an insertion operation and 0 is a removal operation. The index i is 1-indexed, and in the case of a removal operation, the integer j should be ignored.

outputFormat

Output a single line containing n integers separated by a space. These integers represent the final arrangement of the bookshelf slots after performing all operations, where -1 indicates an empty slot.

## sample
5 4
1 1 101
1 3 203
0 1 0
1 2 303
-1 303 203 -1 -1

</p>