#C5446. Book Shelves Manager

    ID: 49096 Type: Default 1000ms 256MiB

Book Shelves Manager

Book Shelves Manager

You are given a bookshelf management system. The system initially has (m) shelves, each with (n) positions, all initialized to 0 (indicating an empty slot). You need to perform two types of operations:

  1. Add Operation: Format: 1 s p b - This operation adds a book with id (b) to shelf number (s) at position (p). Both (s) and (p) are 1-indexed.
  2. Get Operation: Format: 2 s p - This operation queries the book id at shelf (s) and position (p). If no book was added there, the output is 0.

    You are given (q) operations. Your task is to process these operations sequentially and output the results of all get operations in the order they appear.

    Note: Use the following formulas in your explanation if needed:
    (\text{shelf}_{i,j} = 0) initially for all valid (i, j).

inputFormat

The first line of input contains two integers (m) and (n), representing the number of shelves and the number of positions per shelf respectively. The second line contains an integer (q) denoting the number of operations. Each of the following (q) lines describes an operation in one of the following formats:

  • For an add operation: 1 s p b, which adds the book with id (b) at shelf (s) and position (p).
  • For a get operation: 2 s p, which retrieves the book id at shelf (s) and position (p>.

outputFormat

For each get operation (operation type 2), output the book id located at the given shelf and position. Each result should be printed on a new line in the order the operations are performed.## sample

2 5
6
1 1 2 101
1 1 3 102
2 1 2
2 1 3
1 2 1 201
2 2 1
101

102 201

</p>