P5006 [yLOI2018] The Great Jianghu.
Background
> Light snow falls on the long street, and the maple leaves turn red again each year.
> I do not linger only for old friends; in fact, I also love Chang’an.
> The footsteps outside the door are slow; I seem to see the familiar face from the past.
> The story has gone through joys and sorrows many times, and every ending is related to you.
— Yin Lin, *The Great Jianghu*.
This problem was originally named *Space Complexity*.
Description
While listening to *The Great Jianghu*, Fusu controls his character “Paojie” in JX3 and arrives in Chang’an.
In Chang’an there is a quest that requires Fusu to enter an underground “mechanism corridor”. The corridor map is a rectangular grid with $n$ rows and $m$ columns. Each cell contains some monsters or potions. Fusu controls Paojie wandering in the corridor. Sometimes he wants to ask you how much attack power, defense, and lost HP his character (Fusu) currently has.
There are three kinds of potions and one kind of monster on the map, represented by characters `R`, `Q`, `Y`, `M`, respectively. Specifically:
- Character `R` represents an HP potion, which can reduce Paojie’s lost HP $HP$ by $10$. If the currently lost $HP$ is not greater than $10$, then the lost HP becomes $0$.
- Character `Q` represents a strength potion, which increases Paojie’s attack power $ST$ by $5$.
- Character `Y` represents a defense potion, which increases Paojie’s defense $DE$ by $5$.
- Character `M` represents a monster, which will deal damage to Paojie.
Each monster has three attributes: HP $HP_0$, attack power $ST_0$, and defense $DE_0$. To ~~reduce the workload of the validator~~ reduce the difficulty, all monsters have the same attributes.
Once you step onto a monster cell, a battle starts. Fusu will definitely kill the monster, but the monster will also deal some damage to Fusu. Specifically, the damage dealt to Fusu is
$$\max(1, \left\lceil \frac{HP_0}{\max(1, ST - DE_0)}\right\rceil \times \max(1, ST_0 - DE))$$
where $\max(a, b)$ means the larger of $a$ and $b$, and $\lceil x \rceil$ is the smallest integer **not less than** $x$. Values with subscript $0$ are the monster’s parameters, and values without subscripts are the character’s parameters.
You will receive $q$ operations. Each operation is either a query or a move.
For a move, you will be given an additional numeric parameter, which can only be one of $1/2/3/4$, meaning that Paojie moves **left/right/up/down** on the map. Moving up means the row number decreases by one and the column stays the same; other directions are analogous.
For a query, you need to output how much HP Paojie has lost, and the current attack power and defense.
Note that if you enter the same cell multiple times, the potion in that cell will be picked up repeatedly, and the monster will appear again. That is, you may assume that after leaving a cell, it returns to its original state.
Also note that if there is a monster at the initial position, no battle occurs; if there is a potion at the initial position, it will not be picked up.
Input Format
Each test point contains exactly one set of testdata.
The first line contains two integers separated by spaces, representing the number of rows $n$ and columns $m$ of the map.
Lines $2$ to $(n + 1)$ each contain a string of length $m$. The $j$-th character $C_{i, j}$ in line $(i + 1)$ represents the item/creature in the cell at row $i$ and column $j$. In particular, if $C_{i, j}$ is the character `.`, it means there is nothing there, but the cell is passable.
Line $(n + 2)$ contains three integers separated by spaces, representing the monster’s HP $HP_0$, attack power $ST_0$, and defense $DE_0$.
Line $(n + 3)$ contains two integers, representing the character’s initial row $x$ and initial column $y$.
Line $(n + 4)$ contains two integers separated by spaces, representing the character’s initial attack power $ST$ and defense $DE$.
Line $(n + 5)$ contains an integer, representing the number of operations $q$.
Lines $(n + 6)$ to $(n + q + 5)$ each start with an integer $op$, representing the type of this operation.
- If $op = 1$, this operation is a query.
- If $op = 2$, this operation is a move. After a space there will be an integer $d$ as the movement parameter.
Output Format
For each query operation, output one line with three integers separated by single spaces: the character’s lost HP $HP$, and the current attack power $ST$ and defense $DE$.
Explanation/Hint
#### Constraints
| Test Point ID | $n$ | $m$ | $q$ | Special Property |
| :-----------: | :--------: | :--------: | :---------: | :---------------------: |
| $1$ | $=1$ | $=1$ | $=0$ | None |
| $2,3$ | $=1$ | $\leq 10$ | $\leq 1000$ | None |
| $4,5$ | $=1$ | $=1$ | $\leq 1000$ | Guaranteed $op = 1$ |
| $6,7,8$ | $\leq 100$ | $\leq 100$ | $\leq 10^4$ | No monsters on the map |
| $9, 10$ | $\leq 100$ | $\leq 100$ | $\leq 10^4$ | None |
For all test points, it is guaranteed that:
- $1 \leq n, m \leq 100$, $0 \leq q \leq 10^4$.
- $0 \leq ST_0, DE_0, HP_0, ST, DE \leq 100$.
- $1 \leq op \leq 2$, $1 \leq d \leq 4$.
- $C_{i, j}$ can only be one of `.`, `R`, `Q`, `Y`, `M`.
- During the entire movement process, the current row is always a positive integer not greater than $n$, and the current column is always a positive integer not greater than $m$.
Translated by ChatGPT 5