P17713 Red Face Plays pvz (game)
Background
Problem source: [HT-122-Div.3] Walnut CSP-J Mock Contest
Red Face loves playing pvz (Plants vs. Zombies). One day, he saw a somewhat different version of the game.
Description
**Note: the zombies in this problem do not move!**
On a $10^9 \times 10^9$ two-dimensional plane, there are two kinds of units: peashooters and zombies. The direction of increasing $x$ coordinate is defined as right, so two units are in the same row if and only if their $y$ coordinates are equal.
On a lawn, every second Red Face performs one operation:
- `1 x y`: plant a peashooter at row $x$, column $y$.
- `2 x y z`: place a zombie with health $z$ at row $x$, column $y$.
After each operation, the attack rules are as follows:
1. Each peashooter attacks only once in this round. If there are zombies to the right in its row, it deals $1$ point of damage to the first zombie on its right. Here, "the first zombie on the right" means the zombie whose $y$ coordinate equals the peashooter's, whose $x$ coordinate is greater than the peashooter's, and whose $x$ coordinate is the smallest among such zombies.
2. When a zombie is killed in this round, i.e., its health drops to $0$ or below:
- The zombie disappears immediately;
- If the number of attacks on this zombie exceeds its remaining health before being attacked, the excess attacks carry over within the same round and hit the next zombie on its right; if the next zombie is also killed, the extra attacks keep carrying over to the right;
- Peashooters that have already attacked will not attack again in this round. Starting from the next round, they will attack the new first zombie on their right instead.
3. Each round of attacks is executed only once. After the attacks end, output the XOR sum of the health of all currently alive zombies.
Input Format
The first line contains an integer $q$, the number of operations.
Each of the next $q$ lines contains three or four integers, describing one operation.
Output Format
For each operation, after the attacks end, output one line with a single integer, the **XOR sum of the health of all currently alive zombies**.
After all operations are done, output all units that are still alive:
- For a peashooter, output `1 x y`.
- For a zombie, output `2 x y z`, where $z$ is its remaining health.
The output order must satisfy:
1. All peashooters come first;
2. Units of the same kind are sorted by $x$ in ascending order;
3. If the $x$ values are equal, sort by $y$ in ascending order.
Explanation/Hint
### Sample Explanation
**For sample $1$:**
- Second 1: a peashooter is planted at $(1,2)$. There are no zombies, so the peashooter does not attack.
- Second 2: a zombie is placed at $(3,2)$. The peashooter attacks the zombie once, and the zombie's health becomes $24-1=23$.
- Second 3: a peashooter is planted at $(2,2)$. The two peashooters each attack the zombie once, and the zombie's health becomes $23-2=21$.
:::info[For sample $2$:]
1. A zombie with health $50$ is placed at $(1,1)$. The XOR sum of health is $50$.
2. A zombie with health $50$ is placed at $(3,1)$. The XOR sum of health is $50 \oplus 50=0$.
3. A peashooter is planted at $(2,1)$. This peashooter attacks the zombie at $(3,1)$. The XOR sum of health is $50 \oplus 49=3$.
4. A peashooter is planted at $(4,1)$. The peashooter at $(2,1)$ attacks the zombie at $(3,1)$. The XOR sum of health is $50 \oplus 48=2$.
5. A peashooter is planted at $(5,1)$. The peashooter at $(2,1)$ attacks the zombie at $(3,1)$. The XOR sum of health is $50 \oplus 47=29$.
6. A zombie with health $50$ is placed at $(8,1)$. The peashooter at $(2,1)$ attacks the zombie at $(3,1)$, and the peashooters at $(4,1),(5,1)$ each attack the zombie at $(8,1)$. The XOR sum of health is $50 \oplus 46 \oplus 48=44$.
7. A peashooter is planted at $(7,1)$. The peashooter at $(2,1)$ attacks the zombie at $(3,1)$, and the peashooters at $(4,1),(5,1),(7,1)$ each attack the zombie at $(8,1)$. The XOR sum of health is $50 \oplus 45 \oplus 45=50$.
8. A peashooter is planted at $(6,1)$. The peashooter at $(2,1)$ attacks the zombie at $(3,1)$, and the peashooters at $(4,1),(5,1),(6,1),(7,1)$ each attack the zombie at $(8,1)$. The XOR sum of health is $50 \oplus 44 \oplus 41=55$.
9. A zombie with health $50$ is placed at $(1,2)$. The peashooter at $(2,1)$ attacks the zombie at $(3,1)$, and the peashooters at $(4,1),(5,1),(6,1),(7,1)$ each attack the zombie at $(8,1)$. The XOR sum of health is $50 \oplus 43 \oplus 37 \oplus 50=14$.
10. A peashooter is planted at $(2,2)$. The peashooter at $(2,1)$ attacks the zombie at $(3,1)$, and the peashooters at $(4,1),(5,1),(6,1),(7,1)$ each attack the zombie at $(8,1)$. The XOR sum of health is $50 \oplus 42 \oplus 33 \oplus 50=11$.
:::
**For sample $3$:**
Please note: if a zombie is killed in some round, the peashooters on its left **will hit the zombie to its right**.
### Constraints
**This problem uses bundled testing and subtask dependencies.**
::cute-table{tuack}
| Subtask | $q\le$ | $x,y\le$ | Special Property | Score | Subtask Dependencies |
| :----: | :----: | :------: | :------: | :--: | :--------: |
| $0$ | $10^5$ | $10^9$ | A | $0$ | None |
| $1$ | $10$ | $8$ | None | $18$ | None |
| $2$ | $1000$ | $1000$ | ^ | $12$ | $1$ |
| $3$ | ^ | $10^9$ | ^ | $12$ | $1,2$ |
| $4$ | $10^5$ | $1000$ | ^ | $6$ | $1,2$ |
| $5$ | ^ | $10^9$ | B | $9$ | $1$ |
| $6$ | ^ | ^ | C | $9$ | $1$ |
| $7$ | ^ | ^ | None | $34$ | $0 \sim 6$ |
Special properties:
- $A$: it is the sample.
- $B$: there are at most $10$ peashooters.
- $C$: there are at most $10$ zombies.
For $100\%$ of the testdata, it is guaranteed that:
- $1 \le x,y \le 10^9$
- $1 \le z \le 50$
- $1 \le q \le 10^5$
- The coordinates of all peashooters and zombies are pairwise distinct.
Translated by QwenWork