#K57272. Matrix Query Operations

    ID: 30384 Type: Default 1000ms 256MiB

Matrix Query Operations

Matrix Query Operations

You are given an (n \times m) matrix consisting of positive integers and a sequence of (q) queries. There are two types of queries:

  1. Update query: "1 r c x" — set the element at row (r) and column (c) to (x).

  2. Maximum query: "2 r1 c1 r2 c2" — find the maximum element in the submatrix whose upper left corner is at ( (r_1, c_1) ) and lower right corner is at ( (r_2, c_2) ). That is, find [ \max { matrix[i][j] \mid r_1 \le i \le r_2,; c_1 \le j \le c_2 } ]

Input and output are handled via standard input and standard output respectively.

inputFormat

The first line contains two integers (n) and (m) representing the number of rows and columns of the matrix. The next (n) lines each contain (m) positive integers representing the rows of the matrix. The following line contains an integer (q) denoting the number of queries. Each of the next (q) lines contains a query in one of the following formats:

• Update query: 1 r c x (1-indexed) — update the element at row (r) and column (c) to (x).

• Maximum query: 2 r1 c1 r2 c2 (1-indexed) — output the maximum number in the submatrix from row (r_1) to (r_2) and column (c_1) to (c_2).

outputFormat

For each maximum query (queries of type 2), output the maximum value in the specified submatrix on a new line.## sample

3 3
1 2 3
4 5 6
7 8 9
3
2 1 1 3 3
1 2 2 10
2 1 1 3 3
9

10

</p>