luogu#P5006. [yLOI2018] 大美江湖

[yLOI2018] 大美江湖

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.

Problem 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 nn rows and mm 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 HPHP by 1010. If the currently lost HPHP is not greater than 1010, then the lost HP becomes 00.
  • Character Q represents a strength potion, which increases Paojie’s attack power STST by 55.
  • Character Y represents a defense potion, which increases Paojie’s defense DEDE by 55.
  • Character M represents a monster, which will deal damage to Paojie.

Each monster has three attributes: HP HP0HP_0, attack power ST0ST_0, and defense DE0DE_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)\max(a, b) means the larger of aa and bb, and x\lceil x \rceil is the smallest integer not less than xx. Values with subscript 00 are the monster’s parameters, and values without subscripts are the character’s parameters.

You will receive qq 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/41/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 nn and columns mm of the map.

Lines 22 to (n+1)(n + 1) each contain a string of length mm. The jj-th character Ci,jC_{i, j} in line (i+1)(i + 1) represents the item/creature in the cell at row ii and column jj. In particular, if Ci,jC_{i, j} is the character ., it means there is nothing there, but the cell is passable.

Line (n+2)(n + 2) contains three integers separated by spaces, representing the monster’s HP HP0HP_0, attack power ST0ST_0, and defense DE0DE_0.

Line (n+3)(n + 3) contains two integers, representing the character’s initial row xx and initial column yy.

Line (n+4)(n + 4) contains two integers separated by spaces, representing the character’s initial attack power STST and defense DEDE.

Line (n+5)(n + 5) contains an integer, representing the number of operations qq.

Lines (n+6)(n + 6) to (n+q+5)(n + q + 5) each start with an integer opop, representing the type of this operation.

  • If op=1op = 1, this operation is a query.
  • If op=2op = 2, this operation is a move. After a space there will be an integer dd 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 HPHP, and the current attack power STST and defense DEDE.

5 5
MMMMM
RRRRR
QQQQQ
YYYYY
.....
5 5 5
5 1
10 10
8
2 3
1
2 3
2 3
2 3
1
2 2
1
0 10 15
1 15 15
2 15 15

Hint

Constraints

Test Point ID nn mm qq Special Property
11 =1=1 =1=1 =0=0 None
2,32,3 10\leq 10 1000\leq 1000
4,54,5 =1=1 Guaranteed op=1op = 1
6,7,86,7,8 100\leq 100 104\leq 10^4 No monsters on the map
9,109, 10 None

For all test points, it is guaranteed that:

  • 1n,m1001 \leq n, m \leq 100, 0q1040 \leq q \leq 10^4.
  • 0ST0,DE0,HP0,ST,DE1000 \leq ST_0, DE_0, HP_0, ST, DE \leq 100.
  • 1op21 \leq op \leq 2, 1d41 \leq d \leq 4.
  • Ci,jC_{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 nn, and the current column is always a positive integer not greater than mm.

Translated by ChatGPT 5