There is a triangular array with $$$n+1$$$ rows, which is an equilateral triangle pointing up. Each cell has a coordinate $$$(x, y, z)$$$ representing the number of rows it is away from the right slanted side, the bottom side, and the left slanted side respectively. All coordinates satisfy $$$x + y + z = N$$$ and $$$0 \leq x, y, z \leq N$$$.
Each cell contains a value which is initially $$$0$$$.
The triangular array when $$$N = 4$$$. The black triples are coordinates. The red numbers are values. You can perform operations on the array.
In one operation, you can pick a number, then add that number to a parallelogram of cells which has one vertex coinciding with a vertex of the triangle and has edges which are aligned with the edges of the triangle adjacent to that vertex.
More formally, you can perform the following operations on the triangular array:
An operation of the form $$$X \ q_y \ q_z \ c$$$ will add $$$c$$$ to all cells $$$(x, y, z)$$$ such that $$$y \leq q_y$$$ and $$$z \leq q_z$$$. The restrictions on $$$q_y, q_z$$$ and $$$c$$$ are: $$$0 \leq q_y, q_z, q_y + q_z \leq N$$$, and $$$-10^{15} \leq c \leq 10^{15}$$$.
An operation of the form $$$Y \ q_z \ q_x \ c$$$ will add $$$c$$$ to all cells $$$(x, y, z)$$$ such that $$$z \leq q_z$$$ and $$$x \leq q_x$$$. The restrictions on $$$q_z, q_x$$$ and $$$c$$$ are: $$$0 \leq q_z, q_x, q_z + q_x \leq N$$$, and $$$-10^{15} \leq c \leq 10^{15}$$$.
An operation of the form $$$Z \ q_x \ q_y \ c$$$ will add $$$c$$$ to all cells $$$(x, y, z)$$$ such that $$$x \leq q_x$$$ and $$$y \leq q_y$$$. The restrictions on $$$q_x, q_y$$$ and $$$c$$$ are: $$$0 \leq q_x, q_y, q_x + q_y \leq N$$$, and $$$-10^{15} \leq c \leq 10^{15}$$$.
For instance, after the operation $$$X \ 1 \ 2 \ 3$$$, the triangular array would look as follows:
The affected cells are the cells in the green parallelogram. ($$$y \leq 1$$$, and $$$z \leq 2$$$). Their values increase by $$$3$$$. You are also given a triangular region $$$T$$$. Your objective is to use these operations to change the value of all cells in a given triangular region, $$$T$$$, into $$$1$$$, while leaving the rest of the triangular grid as $$$0$$$.
That triangular region will be specified by $$$q_x$$$, $$$q_y$$$, and $$$q_z$$$, $$$0 \leq q_x, q_y, q_z, q_x+q_y, q_y+q_z, q_z+q_x \leq N$$$.
If $$$q_x + q_y + q_z \leq N$$$, then $$$T$$$ contains all cells $$$(x, y, z)$$$ such that $$$x \geq q_x$$$, $$$y \geq q_y$$$, $$$z \geq q_z$$$.
If $$$q_x + q_y + q_z \gt N$$$, then $$$T$$$ contains all cells $$$(x, y, z)$$$ such that $$$x \leq q_x$$$, $$$y \leq q_y$$$, $$$z \leq q_z$$$.
For instance, if $$$q_x = 1$$$, $$$q_y = 1$$$, and $$$q_z = 1$$$, then $$$T$$$ would look as follows:
The purple triangle is $$$T$$$. The red values are the desired ending state of the triangular array. And, if $$$q_x = 2$$$, $$$q_y = 2$$$, and $$$q_z = 2$$$, then $$$T$$$ would look as follows.
The purple triangle is $$$T$$$. Note that it is in the opposite orientation. The red values are the desired ending state of the triangular array. Construct a sequence of at most $$$1000$$$ operations to accomplish the objective.
One line containing $$$N$$$, $$$q_x$$$, $$$q_y$$$, and $$$q_z$$$. $$$(0 \leq N \leq 10^9, 0 \leq q_x, q_y, q_z, q_x+q_y, q_y+q_z, q_z+q_x \leq N)$$$.
—
Tests in subtasks are numbered from $$$1−20$$$ with samples skipped. Each test is worth $$$\frac{100}{20}=5$$$ points.
Tests $$$1-2$$$ satisfy $$$N \leq 15$$$.
Tests $$$3-7$$$ satisfy $$$N \leq 200$$$.
Tests $$$8-10$$$ satisfy $$$q_x, q_y, q_z = 0$$$.
Tests $$$11-20$$$ satisfy no additional constraints.
Output $$$K$$$, the number of operations used. $$$0 \leq K \leq 1000$$$.
Then, output $$$K$$$ lines each contain an operation.
Operations are of the form:
$$$X \ q_y \ q_z \ c$$$, $$$0 \leq q_y, q_z, q_y + q_z \leq N$$$, and $$$-10^{15} \leq c \leq 10^{15}$$$.
$$$Y \ q_z \ q_x \ c$$$, $$$0 \leq q_z, q_x, q_z + q_x \leq N$$$, and $$$-10^{15} \leq c \leq 10^{15}$$$.
$$$Z \ q_x \ q_y \ c$$$, $$$0 \leq q_x, q_y, q_x + q_y \leq N$$$, and $$$-10^{15} \leq c \leq 10^{15}$$$.
2 1 1 1
2 X 1 1 1 X 0 0 -1
The array initially starts out in this state:
After the first operation, the values of cells $$$(2, 0, 0)$$$, $$$(1, 1, 0)$$$, $$$(1, 0, 1)$$$, $$$(0, 1, 1)$$$ increase by $$$1$$$.
After the second operation, the value of cell $$$(2, 0, 0)$$$ increases by $$$-1$$$. (or decreases by $$$1$$$)
Now, this completes the objective, as each cell in $$$T$$$: $$$(1, 1, 0)$$$, $$$(1, 0, 1)$$$, $$$(0, 1, 1)$$$ has value $$$1$$$, and each cell not in $$$T$$$ has value $$$0$$$.
—
Problem Idea: Alex_C
Problem Preparation: Alex_C
Occurrences: Advanced J
| Name |
|---|


