B. Kozak Vus və proqramlaşdırma#8752

B. Kozak Vus və proqramlaşdırma

1 saniyə
64 meqabayt
Asan

Kozak has a favorite robot named Atlas, which he played with a lot during his childhood. Recently, Vus realized he had never tried programming the robot for different tasks, so he started reading the manual. He discovered that Atlas has registers, each numbered starting from , and each register contains bits. This means each register is made up of zeros and ones.

Vus learned that the robot can be programmed using seven specific commands that perform operations on these registers. For simplicity, we will refer to register as the register with the number , and a_i as the number stored in the -th register.

  1. setValue(, ) — Replace the contents of register with those of register . Each bit in register is replaced by the corresponding bit in register , which is equivalent to performing the operation a_i = a_j.

  2. setXor(, , ) — Replace the contents of register with the bitwise XOR of registers and . Each bit in register is replaced by the XOR of the corresponding bits in registers and .

  3. setAnd(, , ) — Replace the contents of register with the bitwise AND of registers and .

  4. setOr(, , ) — Replace the contents of register with the bitwise OR of registers and .

  5. shiftLeft(, ) — Shift all bits in register positions to the left. (See explanation below.)

  6. shiftRight(, ) — Shift all bits in register positions to the right. (See explanation below.)

  7. setNot(, ) — Replace the contents of register with the bitwise NOT of register . Each bit in register is set to if the corresponding bit in register is , and set to if the corresponding bit in register is .

A bitwise XOR of two bits results in if they are the same, and if they are different.

A bitwise AND of two bits results in only if both bits are , and otherwise.

A bitwise OR of two bits results in if at least one bit is , and only if both bits are .

A shift left by positions in a register means that each bit is moved to the left by positions: the value at position becomes the value at position i-x, filled with zeros if i-x is out of bounds. The same logic applies for a shift right, filling zeros from the left.

After reading the manual, Kozak Vus came up with six interesting tasks. He realized that to program the robot for a specific task, he only needs to input a sequence of commands that will solve the task. Suppose is the number of commands executed for a certain task.

Here are the tasks:

Subtask 1: (up to points) The number is stored in register . All other registers are filled with zeros. Let the number be if is even, and if is odd. The task is to ensure that after executing the operations, the number is stored in register .

Subtask 2: (up to points) The number is stored in register , and the number is stored in register . All other registers are filled with zeros. Let z = x + y. The task is to ensure that after executing the operations, the number is stored in register . If the binary representation of requires more than bits, only the first bits should be stored in register .

Subtask 3: (up to points) The number is stored in register . Let be the number of s in the binary representation of . After executing the operations, should be stored in register .

Subtask 4: (up to points) Two different numbers and are stored in registers and , respectively. If x > y, then a = 0 and b = 1; if y > x, then b = 0 and a = 1. The task is to ensure that after executing the operations, the numbers and are stored in registers and , respectively.

Subtask 5: (up to points) The number is stored in register . Let be the number of s in the binary representation of . After executing the operations, the number 2^y - 1 should be stored in register .

Subtask 6: (up to points) Let be an array containing distinct non-negative integers. For each from to , the number a_i is stored in the -th register. Let be the sorted (ascending) array from . After executing the operations, for each from to , the number b_i should be stored in the -th register. The indices in arrays and are -based.

If no initial value is specified for a register, it is filled with zeros at the start. All numbers are between and 2^{64} - 1.

Kozak Vus knows the number of commands needed to solve each task but does not know which commands to use, so he seeks your help. Your task is to find a sequence of commands that will solve each task for any possible input.

Note that you can execute no more than 10^5 commands. Exceeding this limit will result in points and a Wrong Answer verdict. Executing an incorrect request will result in points and a Runtime Error verdict. The result of your solution in each subtask will be the registers where the correct answers reside. Any numbers can be in all other registers.

Qarşılıqlı əlaqə

For each subtask, you need to implement a separate function:

void solve(int n)

where is the subtask number. This function does not take any parameters and does not return anything.

You can use the following functions:

  • void setValue(integer , integer )

    • Assigns the value of register (1 \le j \le 40) to register (1 \le i \le 40).

  • void setXor(integer , integer , integer )

    • Assigns the value of the XOR operation of registers and (1 \le j, k \le 40) to register (1 \le i \le 40).

  • void setAnd(integer , integer , integer )

    • Assigns the value of the AND operation of registers and (1 \le j, k \le 40) to register (1 \le i \le 40).

  • void setOr(integer , integer , integer )

    • Assigns the value of the OR operation of registers and (1 \le j, k \le 40) to register (1 \le i \le 40).

  • void shiftLeft(integer , integer )

    • Shifts register (1 \le i \le 40) left by positions (0 \le x \le 64).

  • void shiftRight(integer , integer )

    • Shifts register (1 \le i \le 40) right by positions (0 \le x \le 64).

  • void setNot(integer , integer )

    • Assigns the bitwise NOT of register (1 \le j \le 40) to register (1 \le i \le 40).

Nümunələr

Suppose the number is stored in register , and the number is stored in register . If we execute the following commands:

setValue(3, 1)setXor(4, 1, 2)setAnd(5, 1, 2)setOr(6, 2, 1)shiftLeft(2, 3)shiftRight(1, 2)setNot(7, 2)

Then the first seven numbers of the register array will look like this: [1, 24, 6, 5, 2, 7, 18446744073709551591].

Nümunə 1

Loading
Loading