#C4146. Grid Query Processing

    ID: 47652 Type: Default 1000ms 256MiB

Grid Query Processing

Grid Query Processing

In this problem, you are given (T) test cases. Each test case consists of an (n \times n) grid initially filled with zeros. You need to process (q) queries on the grid. There are two types of queries:

  1. Update Query: The query is in the form: (1\ x\ y\ val). This sets the value at the cell located at ((x, y)) (1-indexed) to (val).

  2. Maximum Query: The query is in the form: (2\ x_1\ y_1\ x_2\ y_2). This query asks for the maximum value in the subgrid with its top-left cell at ((x_1, y_1)) and bottom-right cell at ((x_2, y_2)).

For each query of the second type, you should output the maximum value found in the specified subgrid. Process the queries in the order they are given for each test case.

inputFormat

The input is given via standard input (stdin). The first line contains an integer (T), the number of test cases. For each test case, the first line contains two integers (n) and (q), where (n) is the size of the grid and (q) is the number of queries. The following (q) lines will each contain a query. A query will be either in the format:

• 1 x y val (to update the cell at ((x, y)) to (val)) or • 2 x1 y1 x2 y2 (to query the maximum value in the subgrid from ((x1, y1)) to ((x2, y2))).

outputFormat

For each query of type 2, output the maximum value found in the specified subgrid on a new line. The outputs from all test cases must be printed in the order in which the queries appear.## sample

2
4 3
2 1 1 4 4
1 2 2 5
2 1 1 4 4
3 3
1 1 1 3
1 2 2 6
2 1 1 2 2
0

5 6

</p>