Machine
Time limit1sMemory limit1024 MB
Recover the hidden permutation P by querying a machine that returns A[P[i]] XOR X for an unknown X, within a limit on the number of queries.
- Level
Medium6 of 10
- Topics
- Bit manipulation, Array, Implementation
- Solved
- No attempts yet
Problem
The ancient Egyptian computer scientists built several machines that shuffled arrays of integers. Thousands of years later, archaeologists discovered one of them and examined it.
The machine takes an array of integers as input. It has a built-in permutation of the numbers from to , which it uses to shuffle the array. is an array of length in which each integer from to appears exactly once.
Due to corrosion, the machine not only shuffles the numbers but also XORs each one with an unknown number . The machine returns an array of length such that
Here is the bitwise XOR operator. For non-negative integers and , the -th bit of is 1 exactly when the -th bits of and differ. is fixed, so it does not change between uses of the machine.
The archaeologists want to know the built-in permutation . Use the machine to find . Each subtask limits how many times the machine can be used and the largest number you can put in array .
Constraints
- for each
- for all