P28877 [洛谷] Portal2
提高-
题目描述

Problem Background

The XM Research Institute of ENLIGHTENED is studying the processing rules of Portal to uncover the source and applications of XM energy. The chief scientist of ENLIGHTENED, Jacks, has discovered the operational rules and methods of this energy, but the methods are extremely complex, making it difficult to manually calculate the answers. Therefore, he needs your assistance to complete the calculations.

Problem Description

The calculation of XM energy by Portal is implemented through two stacks (Stack 0 and Stack 1). The operations on XM energy are as follows:

  • PUSH X NUM
  • Add NUM to the top of Stack X.

  • POP X

  • Delete the top element of Stack X.

  • ADD X

  • Take one element from both Stack 0 and Stack 1, and place their sum into Stack X.

  • SUB X

  • Take one element from both Stack 0 and Stack 1, and place the absolute value of their difference into Stack X.

  • DEL X

  • Clear all elements in Stack X regardless of whether the stack is empty.

  • MOVE X Y

  • Repeatedly move the top element from Stack Y to Stack X and delete the top element from Stack Y until Stack Y is empty.
  • Data guarantees that X and Y are not the same.

  • SWAP

  • Swap all elements between the two stacks.

  • END

  • Indicates the end of commands. Output the elements of Stack 0 and Stack 1 from top to bottom on separate lines. If a stack is empty, output NONE. Data guarantees that the instructions end with END and there is only one END, and SUCCESS should also be output.

For each command line, if the command is executed successfully, output SUCCESS. If the stack is empty when attempting to take or delete elements, or if there is no corresponding command, output UNSUCCESS and do not execute that command.

Input Format

Input multiple lines of commands, ending with the END command.

Output Format

For each operation, output SUCCESS or UNSUCCESS accordingly. For the END command, output the elements in the stacks as described in the command.

Sample Input and Output

Sample Input #1

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

Sample Output #1

SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
UNSUCCESS
SUCCESS
150 30 20 10
NONE

Sample Input #2

PUSH 0 10
PUSH 0 20
PUSH 0 30
PUSH 0 40
PUSH 1 50
PUSH 1 60
MOVE 0 1
END

Sample Output #2

SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
SUCCESS
50 60 40 30 20 10
NONE

Notes

  • For 20% of the data, MOVE and SWAP operations will not occur, and the total number of commands $\leq 100$.
  • For 40% of the data, the total number of commands $\leq 1000$.
  • For 60% of the data, the number of MOVE and SWAP operations will not exceed $10000$, and the total number of commands $\leq 10^5$.
  • For 100% of the data, $0 \leq X, Y \leq 1$, and the total number of commands $\leq 10^6$.
  • Data guarantees that the value of elements in the stack $X$ satisfies $0 \leq x \leq 2^{63}-1$.

Creative source: OIERBBS

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
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