QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 512 MB Points totaux : 100

#7965. Robot

Statistiques

There are $n$ robots arranged in a circle, numbered $0$ to $n-1$ in counter-clockwise order.

Each robot has two hands. Robot $i$ initially has its "left hand" pointing to robot $l_i$ and its "right hand" pointing to robot $r_i$.

Every robot has $m$ lines of "instructions" stored internally. Instructions take the following forms:

Instructions

Instructions are divided into "basic instructions" and "advanced instructions." Advanced instructions are more complex, but there is no fundamental difference between them. The formats and effects of these instructions when "executed" are described below. The word "self" refers to the robot possessing the instruction.

Basic Instructions

  • SLACKOFF: "Slack off", i.e., do nothing.
  • MOVE h z: "Move" the $h$-th hand $z$ positions counter-clockwise. $h=0$ represents the "left hand," and $h=1$ represents the "right hand." The same applies below.
  • SWAP h x y: "Swap" the $x$-th line of instructions of the robot pointed to by the $h$-th hand with the robot's own $y$-th line of instructions.
  • MIRROR h x: "Mirror" (negate) the $x$-th line of instructions of the robot pointed to by the $h$-th hand. This means negating $h$ within the instruction ($0$ becomes $1$, $1$ becomes $0$). Specifically, it has no effect on SLACKOFF instructions; for TRIGGER instructions, it directly modifies the $h$ value within the instruction "executed" upon triggering.
  • REPLACE h x <COMMAND>: "Replace" the $x$-th line of instructions of the robot pointed to by the $h$-th hand with <COMMAND>, where <COMMAND> is a complete instruction.

Advanced Instructions

  • ACTIVATE h: "Activate" the robot pointed to by the $h$-th hand, i.e., "execute" all instructions of that robot in order. The next line is "executed" only after the previous line has finished "executing." Note that while "executing" earlier instructions, later instructions might change; in such cases, the modified instructions must be "executed." This instruction is considered "executed" only after all instructions of the target robot have finished "executing."
  • TRIGGER <COMMANDNAME>: <COMMAND>: <COMMANDNAME> represents the name of an instruction (the first all-caps word in an instruction); <COMMAND> represents a complete "basic instruction." TRIGGER instructions are not "executed" themselves; they are skipped during sequential execution. However, when another robot finishes "executing" an instruction and its "right hand" points to the robot possessing the TRIGGER instruction, the robot's first TRIGGER instruction that meets the following conditions will be "triggered"—the corresponding <COMMAND> is "executed" once:

    • If <COMMANDNAME> is not TRIGGER, the instruction that just finished "executing" must be a <COMMANDNAME> instruction.
    • If <COMMANDNAME> is TRIGGER, the instruction that just finished "executing" must be the instruction that was "executed" when a TRIGGER instruction was triggered.

    After "execution" finishes, the process returns to the original execution sequence.

You need to "activate" these robots one by one in a circle starting from robot $0$, and output information regarding the first $k$ instructions "executed."

Input

The input is read from standard input.

The first line contains three positive integers $n, m, k$.

The next $n$ lines describe the robots in increasing order of their IDs.

For each robot, the first line contains two non-negative integers $l_i, r_i$, representing the IDs of the robots pointed to by the "left hand" and "right hand," respectively.

The next $m$ lines represent the robot's instructions in order. See the problem description for instruction formats.

Output

The output is sent to standard output.

Output $k$ lines, describing the relevant information for the first $k$ instructions that begin "execution." Output one line per instruction before it begins "execution," formatted as follows:

  • For "slack off," output Robot <id> slacks off., where <id> is the integer ID of the robot "executing" the current instruction. The same applies below.
  • For "move," output Robot <id> moves its <side> hand towards Robot <id2>., where <side> is left or right, and <id2> is the ID of the robot the hand points to after the move.
  • For "swap," output Robot <id> swaps a line of command with Robot <id2>., where <id2> is the ID of the robot with which the instruction was swapped.
  • For "mirror," output Robot <id> modifies a line of command of Robot <id2>., where <id2> is the ID of the robot whose instruction was mirrored.
  • For "replace," output Robot <id> replaces a line of command of Robot <id2>., where <id2> is the ID of the robot whose instruction was replaced.
  • For "activate," output Robot <id> activates Robot <id2>., where <id2> is the ID of the robot being activated.
  • TRIGGER instructions themselves are not "executed" and thus do not require output, but when they are "triggered," the corresponding "basic instruction" being "executed" must be output according to the formats above.

Examples

Examples 1

2 2 5
0 0
MOVE 1 1
MOVE 0 1
0 1
TRIGGER MOVE: MOVE 0 1
SLACKOFF

Output 1

Robot 0 moves its right hand towards Robot 1.
Robot 1 moves its left hand towards Robot 1.
Robot 0 moves its left hand towards Robot 1.
Robot 1 moves its left hand towards Robot 0.
Robot 1 slacks off.

Note 1

The "trigger" timing for a TRIGGER instruction is after the instruction finishes "executing." Note that a robot cannot "trigger" its own TRIGGER instructions.

Examples 2

2 2 4
0 1
ACTIVATE 1
SLACKOFF
0 1
SWAP 0 2 2
MIRROR 0 1

Output 2

Robot 0 activates Robot 1.
Robot 1 swaps a line of command with Robot 0.
Robot 1 slacks off.
Robot 0 modifies a line of command of Robot 0.

Note 2

Note that while "executing" earlier instructions, later instructions might change; in such cases, the modified instructions must be "executed."

Examples 3

3 2 6
1 2
ACTIVATE 0
ACTIVATE 0
2 1
SWAP 0 2 2
TRIGGER ACTIVATE: REPLACE 0 2 SLACKOFF
0 1
TRIGGER MIRROR: SLACKOFF
SLACKOFF

Output 3

Robot 0 activates Robot 1.
Robot 1 swaps a line of command with Robot 2.
Robot 1 slacks off.
Robot 2 replaces a line of command of Robot 0.
Robot 0 slacks off.
Robot 1 swaps a line of command with Robot 2.

Note 3

When an ACTIVATE instruction "activates" another robot, it is considered "executed" only after all instructions of that robot have finished "executing."

Examples 4

3 2 8
0 1
SLACKOFF
TRIGGER MOVE: SLACKOFF
1 2
TRIGGER TRIGGER: SLACKOFF
TRIGGER SLACKOFF: MOVE 0 1
2 0
TRIGGER SLACKOFF: MOVE 1 2
TRIGGER TRIGGER: MOVE 1 1

Output 4

Robot 0 slacks off.
Robot 1 moves its left hand towards Robot 2.
Robot 2 moves its right hand towards Robot 1.
Robot 1 slacks off.
Robot 2 moves its right hand towards Robot 0.
Robot 0 slacks off.
Robot 1 slacks off.
Robot 2 moves its right hand towards Robot 2.

Note 4

Only the robot's first TRIGGER instruction that meets the conditions will be "triggered."

Subtasks

It is guaranteed that all instruction formats are correct.

It is guaranteed that the input file size does not exceed $5\mathtt{MB}$.

It is guaranteed that at least $k$ instructions can be "executed."

It is guaranteed that $2\le n\le 100$, $1\le m \le 10$, $1\le k \le 3\times 10^5$.

It is guaranteed that $0\le l_i,r_i < n$.

It is guaranteed that $0\le h \le 1$, $1\le x,y \le m$, $1\le z < n$. All input numbers are integers.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.