#P7899. [Ynoi2006] rprmq2

[Ynoi2006] rprmq2

Problem Description

Given a positive integer mm, you need to maintain an m×mm \times m matrix ai,j,  1i,jma_{i,j},\;1\le i,j\le m, with initial values all 00.

There are mm operations. Each operation gives x,  y,  z0,0,  z0,1,  z1,0,  z1,1x,\;y,\;z_{0,0},\;z_{0,1},\;z_{1,0},\;z_{1,1}.

First, for each 0p,q10\le p,q\le 1, query the maximum value of ai,ja_{i,j} among all positions in the matrix that satisfy [ix]=p,  [jy]=q[i\ge x]=p,\;[j\ge y]=q. Denote the answer as wp,qw_{p,q}.

Then, for every position (i,j)(i,j) in the matrix, add z[ix],[jy]z_{[i\ge x],[j\ge y]} to ai,ja_{i,j}.

The notation [c][c] equals 11 when the condition cc is true, and 00 otherwise.

Input Format

The first line contains one positive integer mm.

Then follow mm lines. Each line contains 66 numbers x,  y,  z0,0,  z0,1,  z1,0,  z1,1x,\;y,\;z_{0,0},\;z_{0,1},\;z_{1,0},\;z_{1,1} representing one operation, with the meaning described above.

Output Format

For each operation, output 44 lines, in order: w0,0,  w0,1,  w1,0,  w1,1w_{0,0},\;w_{0,1},\;w_{1,0},\;w_{1,1}.

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

0
0
0
0
9
5
4
2
12
12
6
12
16
14
14
15
23
23
22
22
28
26
31
31
37
33
37
35
39
42
40
37
44
52
41
41
54
54
47
41

Hint

Idea: ?, Solution: ?, Code: ccz181078, Data: ccz181078.

For 100%100\% of the testdata, 2x,ym2×1052 \le x,y\le m\le 2\times 10^5, 1zi,j1091\le z_{i,j}\le 10^9, and all values are integers.

Translated by ChatGPT 5