#P7827. 「RdOI R3 附加」ACP-I

「RdOI R3 附加」ACP-I

Background

Note: This is not a simulation problem. Please read the entire statement carefully before you start.


Leaderboard

task Shortest Lines Achiever
1 5 std
2 191 __Ultimium__
3 845 dead_X
4 24 囧仙 (jiong xian)
5 77 dqstz
6 15078 寻逍遥2006 (xun xiao yao 2006)
7 211 liqingyang
8 6796

If your solution uses strictly fewer lines than the number on the list, please contact

/user/207996


The problem name ACP has two meanings: Ancient Computer Program and Another Construct Problem.

In 1951, on the eve of the 32-32-th National Olympiad in Informatics winter camp for teenagers, Little A used a Time Transport Interface (Time Transport Interface) to connect to a computer from 2015, and obtained the problems of the 32nd winter camp to practice.

He opened the third problem, "Future Program":

This is an output-only problem with 10 test points.
For each test point, you are given the source code of a program and the input of that program. You need to run the program and save its output.
Unfortunately, these programs are extremely inefficient, and cannot produce output within the 5-hour contest time.

Little A thought about it and decided to try running this problem on a 1951 computer. However, because the 1951 computer has too little storage space, he cannot transfer the attachments and data. Please help Little A write the standard solution to generate testdata.

Problem Description

This is an output-only problem.

Little A's antique computer uses two stacks of 6464-bit unsigned integers, S0S_0 and S1S_1, to store data. Each stack initially contains 10101010^{10^{10}} zeros.

For convenience, let "TxT_x" denote the top element of stack SxS_x. Let the symbols "&\And", "\mid", and "\oplus" represent bitwise AND, bitwise OR, and bitwise XOR operations, respectively.

This computer supports 8 assembly instructions. Unless otherwise stated, all parameters of the following instructions are integers.

Name Parameters Description Pseudocode
and i\textbf{and}\ i i[0,1]i \in [0,1] Set TiT_i to the bitwise AND of TiT_i and the other stack’s top. TiTi&Ti1T_i \gets T_i \operatorname{\And} T_{i \oplus 1}
or i\textbf{or}\ i Set TiT_i to the bitwise OR of TiT_i and the other stack’s top. TiTiTi1T_i \gets T_i \mid T_{i \oplus 1}
xor i\textbf{xor}\ i Set TiT_i to the bitwise XOR of TiT_i and the other stack’s top. TiTiTi1T_i \gets T_i \oplus T_{i \oplus 1}
lsh i j\textbf{lsh}\ i\ j i[0,1],j[0,64]i \in [0,1],j\in[0,64] Set TiT_i to TiT_i left-shifted by jj bits, with natural overflow. TiTi×2jmod264T_i \gets T_i \times 2^j \bmod 2^{64}
rsh i j\textbf{rsh}\ i\ j Set TiT_i to TiT_i right-shifted by jj bits, with natural overflow. TiTi2jT_i \gets \lfloor \dfrac{T_i}{2^j} \rfloor
not i\textbf{not}\ i i[0,1]i\in[0,1] Set TiT_i to the bitwise NOT of TiT_i. Ti(2641)TiT_i \gets (2^{64}-1)-T_i
pop i\textbf{pop}\ i Pop the top element of stack SiS_i. Remove top element of Si\text{Remove top element of }S_i
mov i\textbf{mov}\ i Move TiT_i from SiS_i to the other stack, i.e., to Si1S_{i \oplus 1}. $\text{Push}\ T_i\text{ to }S_{i\oplus 1};\ \textbf{pop}\ i$

You need to use these assembly instructions to implement several computation tasks, where each test point corresponds to a separate task.

Below, "input a1,a2,a_1, a_2, \cdots" means pushing the integers a1,a2,a_1,a_2,\cdots into stack S0S_0 in order, while the zeros at the bottoms of both stacks remain unchanged. Unless otherwise stated, all input numbers are integers in the range [0,2641]\mathbf{[0,2^{64}-1]}.
"Output x1,x2,x_1, x_2, \cdots" means that after the instructions finish running, several integers will be taken out from S1S_1 in order as x1,x2,x_1,x_2,\cdots to check whether the result is correct. Besides these, after execution, all numbers in S0S_0 and all numbers in S1S_1 that are not taken out may be arbitrary.

  1. Input a,ba, b, output b,ab,a. That is, swap the two numbers.
  2. Input a,ba,b, output (ab+264)mod264(a-b+2^{64}) \bmod 2^{64}. That is, compute the difference with natural overflow.
  3. Input a1,a2,,a9;ai[48,57]a_1, a_2,\cdots,a_9; a_i\in[48,57], i.e. ai[0,9]a_i\in[\mathtt{'0'}, \mathtt{'9'}]. Treat a1a9a_1\sim a_9 as a length-99 string under ASCII encoding. You need to reverse the string and then convert it into the corresponding decimal integer and output it. That is, implement a fast input routine. In particular, the string may have leading zeros.
  4. Input aa, output (popcnta)mod2(\operatorname{popcnt}a) \bmod 2. Here popcntx\operatorname{popcnt} x is the number of 11 bits in the binary representation of xx.
  5. Input a,ba,b, output min{a,b}\min\{a,b\}.
  6. Input a,b,pa,b,p, where pp is a non-negative power of 22 or zero. Output (a×b)modp(a\times b) \bmod p. In particular, when p=0p=0, output 00.
  7. Input aa, where both aa and the answer are non-negative powers of 22 or zero, output a\sqrt a.
  8. Input a,b;1a,b63a,b;1\le a,b \le 63, output gcd(a,b)\gcd(a,b), i.e., the greatest common divisor of a,ba,b.

Input Format

Since the setter does not want to make this a big simulation problem, the assembly simulation part is provided in the attachment.

In the distributed files, there are checker.cpp and 1.ans ~ 8.ans. Among them, checker.cpp provides simple implementations of several assembly instructions. You can use checker.cpp to test your program. Compile checker.cpp with g++ checker.cpp -o checker -std=c++11 into an executable, then run checker *.in *.out *.ans. The checker will output your results and the score for that test point. Here *.in contains the input data given to the instructions, one per line, ending at EOF; *.out stores your instructions; *.ans refers to the .ans files in the distributed package.

Note: This checker is only a sample and does not have the ability to verify correctness.

Output Format

Please write the instructions for each task into 1.out ~ 8.out, then pack them into a zip and submit.

123456789
2147483648
2147483648
123456789
2147483647998244353
9982443532147483647
10611784189560312322
51
53
51
52
52
50
56
57
57
998244353
233456
1
2147483647998244353
9223372036854775808
2147483647998244353
2147483647998244353
9982443532147483647
9223372036854775808

7806477557104029183
4611686018427387904

2147483648
24 32
8
输入 a,b。输出 a 按位异或 b 的结果。
mov 0
xor 1
没有输入,输出数字 6。
not 1
lsh 1 62
rsh 1 61

Hint

Sample Explanation

The above "sample groups 181\sim 8" represent the sample input/output for subtasks 181\sim8. "Sample groups 9109\sim10" are one shortest program implementation for an example problem.


Scoring

Let * denote the test point index. If your instructions (*.out) do not correctly complete the computation, you get 00 points. Otherwise, let the number of instructions you used be cntcnt. If there are xx numbers in *.ans that satisfy cnt\ge cnt, then you get xx points for that test point.


Notes

Although you are allowed to submit up to 999999999999 lines of instructions, due to Luogu’s time limit for running the checker, your instruction length is forced to have a strange upper bound: approximately 2×1052\times 10^5. If you exceed this length, the checker may time out and cause UKE.

Due to the nature of Luogu output-only problems, if you cannot solve some tasks, please put an empty *.out file as a placeholder in the zip, where * is the task number. Otherwise, the whole problem may have mismatched answers (for example, 2.out being submitted to test point 11), causing the following test points to become 00 points.

Translated by ChatGPT 5