#P7899. Matrix Query and Update

    ID: 21084 Type: Default 1000ms 256MiB

Matrix Query and Update

Matrix Query and Update

You are given a positive integer (m) which denotes both the dimensions of an (m \times m) matrix and the number of operations. The matrix (a_{i,j}) (for (1 \le i,j \le m)) is initially filled with zeroes.

For each of the (m) operations, you are given six integers: (x,; y,; z_{0,0},; z_{0,1},; z_{1,0},; z_{1,1}) (with (1 \le x,y \le m)). For the current operation, consider the indicator function defined by [ [i \ge x] = \begin{cases} 1 & \text{if } i \ge x,\ 0 & \text{otherwise.} \end{cases} ] and similarly ([j \ge y]).

First, for each (p,q \in {0,1}), you must query the maximum value among all matrix entries (a_{i,j}) such that ([i \ge x] = p) and ([j \ge y] = q). Denote these values by (w_{p,q}). For regions that do not contain any cells, the maximum is defined as (-10^{18}).

After performing the queries, update every matrix element (a_{i,j}) by adding the value (z_{[i \ge x],[j \ge y]}) where the indices of (z) are determined by the indicator functions on (i) and (j).

For each operation, output one line containing four integers: (w_{0,0},; w_{0,1},; w_{1,0},; w_{1,1}) (in that order).

inputFormat

The first line contains a positive integer (m) representing both the size of the matrix and the number of operations.

Each of the following (m) lines contains six integers: (x,; y,; z_{0,0},; z_{0,1},; z_{1,0},; z_{1,1}). It is guaranteed that (1 \le x,y \le m), and the matrix is 1-indexed.

outputFormat

For each operation, output a single line containing four integers: (w_{0,0},; w_{0,1},; w_{1,0},; w_{1,1}) separated by spaces. If a queried region is empty, output (-10^{18}) as its result.

sample

2
1 1 1 2 3 4
2 2 -1 -2 -3 -4
-1000000000000000000 -1000000000000000000 -1000000000000000000 0

4 4 4 4

</p>