luogu#P4940. Portal 2
Portal 2
Background
The “XM Institute” of ENLIGHTENED in a certain place is studying the processing rules of Portals, trying to reveal the source of “XM energy” and how to use it. ENLIGHTENED’s chief scientist Jacks has found the rules and methods for computing this energy, but the method is very complex. It is hard to get the answer by manual calculation, so he needs your help to finish the computation.
Problem Description
Portal computes “XM energy” using stacks (stack and stack ). The operations on “XM energy” are as follows:
-
PUSH X NUM: Push onto the top of stack . -
POP X: Delete the top element of stack . -
ADD X: Take out one element from stack and one element from stack , and push their sum onto stack . -
SUB X: Take out one element from stack and one element from stack , and push the absolute value of their difference onto stack . -
DEL X: Clear all elements in stack , regardless of whether the stack is empty. -
MOVE X Y: Repeat until stack is empty: push the top element of stack onto stack , then delete the top element of stack (the testdata guarantees that and are different). -
SWAP: Swap all elements of the two stacks. -
END: Indicates the end of commands. Then output, on two separate lines, the values in stack and stack from top to bottom. If a stack has no elements, outputNONE. The testdata guarantees that the commands end withENDand there is only oneEND. You also need to outputSUCCESS. -
Correction: there will be no such invalid operations.AKNOIand so on are invalid operations, and invalid operations are not followed by numbers.
For each command line: if the current command is executed successfully, output SUCCESS. If, when taking out or deleting elements, the required stack is empty, or if there is no corresponding command, output UNSUCCESS and do not execute that command line.
Input Format
Input several lines of commands, ending with the END command.
Output Format
For each operation, output SUCCESS or UNSUCCESS accordingly. For END, output the stack elements as described in the command description.
PUSH 0 10
PUSH 0 20
PUSH 0 30
PUSH 0 40
PUSH 1 50
PUSH 1 60
ADD 0
ADD 0
ADD 0
END
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
UNSUCCESS
SUCCESS
150 30 20 10
NONE
PUSH 0 10
PUSH 0 20
PUSH 0 30
PUSH 0 40
PUSH 1 50
PUSH 1 60
MOVE 0 1
END
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
50 60 40 30 20 10
NONE
Hint
Let the total number of commands be .
For of the testdata, it is guaranteed that there will be no MOVE or SWAP operations, and .
For of the testdata, .
For of the testdata, it is guaranteed that the number of MOVE and SWAP operations will not exceed , and .
For of the testdata, .
The testdata guarantees that in all cases, the value of any element in the stacks satisfies .
Translated by ChatGPT 5