题目描述
Problem Background
Note: This is not a simulation problem. Please read the entire problem statement thoroughly before starting.
Leaderboard
| Task | Shortest Lines | Achiever |
|---|---|---|
| 1 | 5 | std |
| 2 | 191 | Ultimium |
| 3 | 845 | dead_X |
| 4 | 24 | 囧仙 |
| 5 | 77 | dqstz |
| 6 | 15078 | 寻逍遥2006 |
| 7 | 211 | liqingyang |
| 8 | 6796 | liqingyang |
If your solution has fewer lines than those listed, please contact @yzy1 to have your score added to the leaderboard.
The title ACP has two meanings: Ancient Computer Program and Another Construct Problem.
In 1951, just before the -32nd National Olympiad in Informatics Winter Camp, Little A used a Time Transport Interface (Time Transport Interface) to connect to a computer from 2015 and obtained the problems from the 32nd Winter Camp for practice.
He opened the third problem, "Future Program":
This is a submission-answer problem with 10 test cases.
For each test case, you will receive a piece of source code and its input. You need to run this program and save its output.
Unfortunately, these programs are extremely inefficient and cannot produce an output within the 5-hour competition time.
Little A thought about it and decided to try running this problem on a 1951 computer. However, due to the limited storage space of the 1951 computer, he was unable to transmit the problem attachments and data. Please help Little A create data with the standard (std) program.
Problem Description
This is a submission-answer problem.
Little A's antique computer uses two stacks $S_0$ and $S_1$ to store data, each containing $10^{10^{10}}$ zeros initially.
For convenience, "T_x" denotes the top element of stack $S_x$. The symbols "$\And$", "$\mid$", and "$\oplus$" represent bitwise AND, OR, and XOR operations, respectively.
The computer supports 8 assembly instructions. Unless specified otherwise, the parameters for these instructions are integers.
| Name | Parameters | Description | Pseudocode |
|---|---|---|---|
| $\textbf{and}\ i$ | $i \in [0,1]$ | Set $T_i$ to the result of bitwise AND with the top of the other stack. | $T_i \gets T_i \operatorname{\And} T_{i \oplus 1}$ |
| $\textbf{or}\ i$ | $i \in [0,1]$ | Set $T_i$ to the result of bitwise OR with the top of the other stack. | $T_i \gets T_i \mid T_{i \oplus 1}$ |
| $\textbf{xor}\ i$ | $i \in [0,1]$ | Set $T_i$ to the result of bitwise XOR with the top of the other stack. | $T_i \gets T_i \oplus T_{i \oplus 1}$ |
| $\textbf{lsh}\ i\ j$ | $i \in [0,1], j \in [0,64]$ | Set $T_i$ to the result of left shift by $j$ bits, naturally overflowing. | $T_i \gets T_i \times 2^j \bmod 2^{64}$ |
| $\textbf{rsh}\ i\ j$ | $i \in [0,1], j \in [0,64]$ | Set $T_i$ to the result of right shift by $j$ bits, naturally overflowing. | $T_i \gets \lfloor \dfrac{T_i}{2^j} \rfloor$ |
| $\textbf{not}\ i$ | $i \in [0,1]$ | Set $T_i$ to the bitwise NOT of $T_i$. | $T_i \gets (2^{64}-1)-T_i$ |
| $\textbf{pop}\ i$ | $i \in [0,1]$ | Pop the top element from stack $S_i$. | Remove top element of $S_i$ |
| $\textbf{mov}\ i$ | $i \in [0,1]$ | Move $T_i$ from $S_i$ to the other stack. | Push $T_i$ to $S_{i\oplus 1}$; Pop $i$ |
You need to use these assembly instructions to perform several computational tasks, each corresponding to a separate test case. Below, "input $a_1, a_2, \cdots$" means to push the integers $a_1, a_2, \cdots$ sequentially into stack $S_0$, leaving the zeros at the bottom of both stacks unchanged. Unless specified otherwise, the input numbers are within the range $\mathbf{[0, 2^{64}-1]}$. "Output $x_1, x_2, \cdots$" means to sequentially pop several integers from $S_1$ after the instructions are executed to check if the results $x_1, x_2, \cdots$ are correct. Additionally, all numbers in $S_0$ and any numbers in $S_1$ that are not popped can be any value after the instructions are executed.
- Input $a, b$, output $b, a$. This swaps the two numbers.
- Input $a, b$, output $(a-b+2^{64}) \bmod 2^{64}$. This calculates the difference between the two numbers, naturally overflowing.
- Input $a_1, a_2, \cdots, a_9; a_i \in [48, 57]$, i.e., $a_i \in [\mathtt{'0'}, \mathtt{'9'}]$. Treat $a_1 \sim a_9$ as a string of length 9 in ASCII encoding, and you need to reverse this string and convert it to a corresponding decimal integer for output. This implements a fast input reader. Note that the string may have leading zeros.
- Input $a$, output $(\operatorname{popcnt} a) \bmod 2$. Here, $\operatorname{popcnt} x$ represents the number of 1s in the binary representation of $x$.
- Input $a, b$, output $\min\{a, b\}$.
- Input $a, b, p$, where $p$ is a non-negative power of 2 or zero. Output $(a \times b) \bmod p$. Specifically, when $p = 0$, output 0.
- Input $a$, where both $a$ and the answer are non-negative powers of 2 or zero. Output $\sqrt{a}$.
- Input $a, b; 1 \le a, b \le 63$, output $\gcd(a, b)$, the greatest common divisor of $a$ and $b$.
Input and Output Format
Input Format
Since the problem setter does not want to make this a large-scale simulation, the assembly simulation part is provided in the attachments.
In the distributed files, there are checker.cpp and 1.ans ~ 8.ans. checker.cpp provides simple implementations of several assembly instructions. You can use checker.cpp to test your program. Compile checker.cpp into an executable with g++ checker.cpp -o checker -std=c++11 and then run checker *.in *.out *.ans. checker will provide your output results and the score for that test case. Here, *.in contains the input data provided to the instructions, one per line, ending with EOF; *.out stores your instructions; *.ans refers to the .ans files in the distributed files.
Note: This checker is for demonstration purposes only and does not verify correctness.
Output Format
Please write the instructions corresponding to each task into 1.out ~ 8.out and package them into a zip file for submission.
Sample Input and Output
Sample Input #1
123456789
2147483648
Sample Output #1
2147483648
123456789
Sample Input #2
2147483647998244353
9982443532147483647
Sample Output #2
10611784189560312322
Sample Input #3
51
53
51
52
52
50
56
57
57
Sample Output #3
998244353
Sample Input #4
233456
Sample Output #4
1
Sample Input #5
2147483647998244353
9223372036854775808
Sample Output #5
2147483647998244353
Sample Input #6
2147483647998244353
9982443532147483647
9223372036854775808
Sample Output #6
7806477557104029183
Sample Input #7
4611686018427387904
Sample Output #7
2147483648
Sample Input #8
24 32
Sample Output #8
8
Sample Input #9
Input a, b. Output the result of a bitwise XOR of a and b.
Sample Output #9
mov 0
xor 1
Sample Input #10
No input, output the number 6.
Sample Output #10
not 1
lsh 1 62
rsh 1 61
Notes
Sample Explanation
The "Sample Groups $1\sim 8$" represent the sample input and output for subtasks 1 through 8. "Sample Groups $9\sim10$" provide an example of the shortest program implementation for a problem.
Scoring Method
Let * represent the test case number. If your submitted instructions (*.out) do not correctly complete the calculation, you receive zero points. Otherwise, let $cnt$ be the number of instructions you used. If there are $x$ numbers in *.ans that are $\ge$, you score $x$ points for that test case.
Attention
Although we allow you to submit up to $999999$ lines of instructions, due to the time limit on the Luogu checker, your instruction length is artificially capped at approximately $2 \times 10^5$. Instructions exceeding this length may result in a UKE due to checker timeout.
Due to the nature of Luogu's submission-answer problems, if you do not know how to solve some tasks, please place an empty *.out file in the zip package as a placeholder, where * represents the task number. Otherwise, your entire problem may have answer misalignment (e.g., 2.out submitted to test case 1), resulting in subsequent test cases scoring zero points.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分