For anyone who still have doubts about the problem description:
1. The country is divided in N x M regions, where (1 <= N, M <= 500). [It is not
N x N as stated.]
2. All coordinates are given as (ROW, COLUMN), where (1 <= ROW <= N) and (1 <= COLUMN <= M). For instance, region (1, 2) is the region of row 1 and column 2. [It does not
follow the conventional use of X and Y for column and row, respectively.] A rectangle grid is defined by its upper-left coordinate and then its bottom-right coordinate.
3. The queries are either "q R1 C1 R2 C2", where (R1, C1)-(R2, C2) defines a grid containing one or many regions; or "c R C V", where V is the new value for region (R, C). [The description is faulty, but the example is correct.]
Therefore, the input for the problem is better described along these lines:
In the first line you will find N and M, respectively the number of rows and columns of the country map, where (1 <= N, M <= 500). The next N lines contain M integers each and describe the population of each region, that is, the j-th column of the i-th row denotes the population of region (i, j), where (1 <= i <= N, 1 <= j <= M). The next line contains the number of queries Q, where (Q <= 40000), followed by Q lines representing the queries. Each query has one of the following formats: (1) the character 'q' followed by four integers R1 C1 R2 C2, which describe a rectangular grid of upper-left coordinate (R1, C1) and bottom-right coordinate (R2, C2), where (1 <= R1, R2 <= N and 1 <= C1, C2 <= M); or (2) the character 'c' followed by three integers R C V, which describe the new population value of the region of coordinate (R, C), where (1 <= R <= N, 1 <= C <= M).
For each 'q'-query, you must output the greatest population among all regions inside the specified grid, as well as the least population, is this order. For each 'c'-query, you must change the population value of region (R, C) to the new value that was given.
Code: Select all
1 2 3 4 5
0 9 2 1 3
0 2 3 4 1
0 1 2 4 5
8 5 3 1 4
q 1 1 2 3
c 2 3 10
q 1 1 5 5
q 1 2 2 2
The country is defined by 5x5 regions, where the matrix that represents the population distribution is given is the following five lines. Next, there are four queries. The first inquires about the regions on the grid (1,1)-(2,3), that is,
1 2 3
0 9 2
The second updates the value of region (2, 3), which was previously 2, to the new value of 10. The third query inquires about all regions, and the last query inquires about the regions on the grid (1,2)-(2,2):