#P8470. [Aya Round 1 E] 乙(two)

[Aya Round 1 E] 乙(two)

Problem Description

Define the “lateral surface area” of a 3D shape built from some unit cubes (cubes with side length 11) as follows: for every cube, if its front, back, left, or right face is not tightly adjacent to another cube, then that face is counted in the lateral surface area.

Maintain a rectangular ground plane with infinite length and width. The ground is divided into unit grid cells of side length 11. There are nn operations. In each operation, choose a cell (xi,yi)(x_i, y_i) and stack ziz_i unit cubes upward at that position. After each operation, output the “lateral surface area” of the whole 3D shape.

Input Format

  • The first line contains an integer nn.
  • The next nn lines each contain three integers xi,yi,zix_i, y_i, z_i.

Output Format

  • Output nn lines in total, each line containing one integer, representing the “lateral surface area” of the 3D shape after each operation.
3
1 1 2
1 3 3
1 2 4
8
20
26
6
1 2 1
2 1 4
2 3 8
3 2 6
2 2 2
2 2 11
4
20
52
76
70
90

Hint

Explanation of Sample 1

As shown in the figure, set up a 3D Cartesian coordinate system. The xx-axis points south, the yy-axis points east, and the zz-axis points upward. Due to technical limitations, only an oblique drawing is provided here; please imagine how the 3D shape looks from other angles. The green part in the figure is exactly the lateral surface of the 3D shape.

After the first operation, a shape of height 22 is placed at position (1,1)(1, 1), and the lateral surface area is 88.

After the second operation, a shape of height 33 is placed at position (1,3)(1, 3), and the lateral surface area is 1212. Since the two shapes do not touch, we can directly add the lateral surface area of the first shape, so the total lateral surface area is 2020.

After the third operation, a shape of height 44 is placed at position (1,2)(1, 2). Since some faces come into contact, the areas corresponding to those faces are not counted in the lateral surface area. It is easy to see that the total lateral surface area is 2626.


To emphasize again, each stacking operation adds another ziz_i cubes on top of the existing cubes at that position. For example, the figure below shows the result of first executing 2 2 1\verb!2 2 1! and then executing 2 2 3\verb!2 2 3!.

Additional Samples

  • Sample 33 can be found in the attached files two3.in/two3.ans\textbf{\textit{two3.in/two3.ans}}. This sample satisfies the limits of test point 44.
  • Sample 44 can be found in the attached files two4.in/two4.ans\textbf{\textit{two4.in/two4.ans}}. This sample satisfies the limits of test point 77.
  • Sample 55 can be found in the attached files two5.in/two5.ans\textbf{\textit{two5.in/two5.ans}}. This sample satisfies the limits of test point 1010.
  • Sample 66 can be found in the attached files two6.in/two6.ans\textbf{\textit{two6.in/two6.ans}}. This sample satisfies the limits of test point 1313.
  • Sample 77 can be found in the attached files two7.in/two7.ans\textbf{\textit{two7.in/two7.ans}}. This sample satisfies the limits of test point 2020.

Constraints

$$\def\arraystretch{1.5} \begin{array}{|c|c|c|c|c||c|c|c|c|c|} \hline \textbf{\textsf{\#}} & \bm{{n \le }} & \bm{{x,y \le}} & \bm{{z \le}} & \textbf{\textsf{Special property}} & \textbf{\textsf{\#}} & \bm{{n \le }} & \bm{{x,y \le}} & \bm{{z \le}} & \textbf{\textsf{Special property}} \cr\hline 1 & 1 & 1 & 10 & - & 14 & 10^3 & 10^3 & 10^3 & - \cr\hline 2 & 2 & 5 & 10 & - & 15 & 10^3 & 10^3 & 10^9 & - \cr\hline 3 & 10 & 5 & 10 & - & 16 & 10^3 & 10^9 & 10^9 & - \cr\hline 4 & 100 & 100 & 100 & - & 17 & 10^5 & 10^9 & 10^9 & \textbf{AB} \cr\hline 5 & 10^3 & 10^3 & 10^3 & \textbf{AB} & 18 & 10^5 & 10^9 & 10^9 & \textbf{A} \cr\hline 6 & 10^3 & 10^3 & 10^9 & \textbf{AB} & 19 & 10^5 & 10^9 & 10^9 & \textbf{B} \cr\hline 7 & 10^3 & 10^9 & 10^9 & \textbf{AB} & 20 & 10^5 & 10^9 & 10^9 & - \cr\hline 8 & 10^3 & 10^3 & 10^3 & \textbf{A} & 21 & 2\times 10^5 & 10^9 & 10^9 & - \cr\hline 9 & 10^3 & 10^3 & 10^9 & \textbf{A} & 22 & 2\times 10^5 & 10^9 & 10^{12} & - \cr\hline 10 & 10^3 & 10^9 & 10^9 & \textbf{A} & 23 & 2\times 10^5 & 10^9 & 10^{13} & \textbf{A} \cr\hline 11 & 10^3 & 10^3 & 10^3 & \textbf{B} & 24 & 2\times 10^5 & 10^9 & 10^{13} & - \cr\hline 12 & 10^3 & 10^3 & 10^9 & \textbf{B} & 25 & 3\times 10^5 & 10^9 & 10^{13} & - \cr\hline 13 & 10^3 & 10^9 & 10^9 & \textbf{B} &&&&&\cr\hline \end{array}$$
  • Special constraint A\bf A: 1ijn\forall 1 \le i\le j \le n, we have xi=xjx_i = x_j.
  • Special constraint B\bf B: 1ijn\forall 1 \le i\le j \le n, we have (xi,yi)(xj,yj)(x_i, y_i) \ne (x_j, y_j).

For 100%100\% of the testdata, it is guaranteed that 1n3×1051 \le n \le 3 \times 10^5, 1x,y1091 \le x, y \le 10^9, and 1z10131 \le z \le 10^{13}.

Translated by ChatGPT 5