P4940 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.
Description
Portal computes “XM energy” using $2$ stacks (stack $0$ and stack $1$). The operations on “XM energy” are as follows:
- `PUSH X NUM`: Push $NUM$ onto the top of stack $X$.
- `POP X`: **Delete** the top element of stack $X$.
- `ADD X`: **Take out** one element from stack $0$ and one element from stack $1$, and push their sum onto stack $X$.
- `SUB X`: **Take out** one element from stack $0$ and one element from stack $1$, and push the absolute value of their difference onto stack $X$.
- `DEL X`: **Clear** all elements in stack $X$, regardless of whether the stack is empty.
- `MOVE X Y`: Repeat until stack $Y$ is empty: push the top element of stack $Y$ onto stack $X$, then delete the top element of stack $Y$ (**the testdata guarantees that $X$ and $Y$ 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 $0$ and stack $1$ from top to bottom. If a stack has no elements, output `NONE`. The testdata guarantees that the commands end with `END` and there is only one `END`. You also need to output `SUCCESS`.
- ~~`AKNOI` and so on are invalid operations, and **invalid operations are not followed by numbers**.~~ **Correction: there will be no such invalid operations.**
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.
Explanation/Hint
Let the total number of commands be $n$.
For $20\%$ of the testdata, it is guaranteed that there will be no `MOVE` or `SWAP` operations, and $1\le n \leq 100$.
For $40\%$ of the testdata, $1\le n \leq 1000$.
For $60\%$ of the testdata, it is guaranteed that the number of `MOVE` and `SWAP` operations will not exceed $10000$, and $1\leq n \leq 10^5$.
For $100\%$ of the testdata, $0 \leq X,Y \leq 1,1\leq n \leq 10^6$.
**The testdata guarantees that in all cases, the value $X$ of any element in the stacks satisfies $0 \leq X \leq 2^{63}-1$.**
[Problem idea source: OIERBBS](https://www.oierbbs.cn)。
Translated by ChatGPT 5