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 22 stacks (stack 00 and stack 11). The operations on “XM energy” are as follows:

  • PUSH X NUM: Push NUMNUM onto the top of stack XX.

  • POP X: Delete the top element of stack XX.

  • ADD X: Take out one element from stack 00 and one element from stack 11, and push their sum onto stack XX.

  • SUB X: Take out one element from stack 00 and one element from stack 11, and push the absolute value of their difference onto stack XX.

  • DEL X: Clear all elements in stack XX, regardless of whether the stack is empty.

  • MOVE X Y: Repeat until stack YY is empty: push the top element of stack YY onto stack XX, then delete the top element of stack YY (the testdata guarantees that XX and YY 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 00 and stack 11 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.

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 nn.

For 20%20\% of the testdata, it is guaranteed that there will be no MOVE or SWAP operations, and 1n1001\le n \leq 100.

For 40%40\% of the testdata, 1n10001\le n \leq 1000.

For 60%60\% of the testdata, it is guaranteed that the number of MOVE and SWAP operations will not exceed 1000010000, and 1n1051\leq n \leq 10^5.

For 100%100\% of the testdata, 0X,Y1,1n1060 \leq X,Y \leq 1,1\leq n \leq 10^6.

The testdata guarantees that in all cases, the value XX of any element in the stacks satisfies 0X26310 \leq X \leq 2^{63}-1.

Problem idea source: OIERBBS

Translated by ChatGPT 5