LCC '21 Contest 2 J5 - Spadunk

View as PDF

Submit solution

Points: 7
Time limit: 3.0s
Memory limit: 64M

Author:
Problem type

Blackflopper inc™️ have begun a new space exploratory program! Their first unit, the Spadunk-00, has now reached orbit around a planet.

Spadunk-00's onboard data transformation system represents its current position in terms of the planet. In other words, the planet will be the origin of a coordinate system, and Spadunk-00's position can be represented as a 2-d coordinate (x, y).

Spadunk-00 works in a peculiar way. The engineers send a series of commands, all of which either adds a line to the onboard program in Spadunk-00, or executes the program. Prior to the first command issued, the program on Spadunk-00 is empty. Each command can be one of three types:

move(x, y) - adds an instruction to the onboard program. When Spadunk-00 runs the program (which occurs when it runs the execute() command), the instruction this command adds moves Spadunk-00 by (x, y)

blast(v) - adds an instruction to the onboard program. When Spadunk-00 runs the program (which occurs when it runs the execute() command), the instruction this command adds blasts Spadunk-00 away from or towards the planet, so that it is now v times as far from the planet (which is the origin). In other words, it multiplies both the x coordinate and y coordinate by v.

Note that move(x, y) and blast(v), by themselves, do nothing. However, they add an instruction to Spadunk-00's program, which, when run through the execute() method, would update its position.

execute() - runs the program, executing each instruction which was stored in Spadunk-00 through the move() and blast() commands. The program is run sequentially, running each instruction starting from the earliest added to the latest, thus updating the position of Spadunk-00. All of the lines that were previously on Spadunk-00's program will remain in the program.

Unfortunately, the engineers soon realized that the whiteflipper nation have intercepted their signal and provided Spadunk-00 with M commands already! Can you, Spock, find out the final coordinates of the Spadunk-00?

Constraints

In all subtasks,

0\le M\le 2\cdot10^5.

At any point in time, the absolute value of Spadunk-00's x coordinate and y coordinate will not exceed 10^9.

v\ge 0

Subtask 1 [10%]

M\le10^3.

Subtask 2 [30%]

Y=y=0. In other words, at any point in time, Spadunk-00's y-coordinate will be 0.

Subtask 3 [60%]

No additional constraints.

Input Specification

The first line contains two decimals, X and Y, representing the current coordinates of Spadunk-00.

The second line contains a nonnegative integer, M, representing the number of commands that the Whiteflipper nation sent to Spadunk-00.

The next M lines are in one of the following formats:

1 x y - the whiteflipper nation sends the move(x, y) command to Spadunk-00. x and y are decimals with absolute values less than 10^9.

2 v - the whiteflipper nation sends the blast(v) command to Spadunk-00. v is a decimal with absolute value less than 10^9.

3 - the whiteflipper nation sends the execute() command to Spadunk-00.

Output Specification

Two decimals on one line, the x and y coordinate of Spadunk-00 after it runs all of the commands. Only when printing the final answer, round the x and y coordinates to the nearest hundredth, printing out two digits after the decimal point. It is recommended to use double instead of float due to precision differences.

Sample Input

3.0 4.0
6
1 2.0 3.0
2 2.0
3
1 -2.0 5.0
2 0.5
3

Sample Output

11.00 19.50

Sample Explanation

After the first and second commands, the program is:

move(2.0, 3.0)

blast(2.0)

The third command executes this program, the coordinates are updated as such:

move(2.0, 3.0): (3.0,4.0) -> (3.0+2.0, 4.0+3.0)=(5.0, 7.0)

blast(2.0): (5.0, 7.0) -> (5.0\cdot2.0, 7.0\cdot2.0)=(10.0, 14.0)

The fourth and fifth command add two more commands. Now, our program is:

move(2.0, 3.0)

blast(2.0)

move(-2.0, 5.0)

blast(0.5)

The final command executes the program once more. The coordinates are updated as such:

move(2.0, 3.0): (10.0, 14.0) -> (12.0, 17.0)

blast(2.0): (12.0, 17.0) -> (24.0, 34.0)

move(-2.0, 5.0): (24.0, 34.0) -> (22.0, 39.0)

blast(0.5): (22.0, 39.0) -> (11.0, 19.5)

Thus, our final coordinate is (11, 19.5). When printing your final answer, remember to round to the nearest hundredth and print out two decimal places. Thus, we print out 11.00 19.50


Comments

There are no comments at the moment.