Under construction

Still being built. Things may change

Machine

Time limit1sMemory limit1024 MB

Summary
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 AA of NN integers as input. It has a built-in permutation PP of the numbers from 00 to N−1N-1, which it uses to shuffle the array. PP is an array of length NN in which each integer from 00 to N−1N-1 appears exactly once.

Due to corrosion, the machine not only shuffles the numbers but also XORs each one with an unknown number XX. The machine returns an array BB of length NN such that

B[i]=A[P[i]]⊕X(0≤i<N)B[i] = A[P[i]] \oplus X \quad (0 \le i < N)

Here ⊕\oplus is the bitwise XOR operator. For non-negative integers cc and dd, the jj-th bit of c⊕dc \oplus d is 1 exactly when the jj-th bits of cc and dd differ. XX is fixed, so it does not change between uses of the machine.

The archaeologists want to know the built-in permutation PP. Use the machine to find PP. Each subtask limits how many times the machine can be used and the largest number you can put in array AA.

Constraints

  • 1≤T≤1001 \le T \le 100
  • 3≤N≤1283 \le N \le 128
  • 0≤X≤2550 \le X \le 255
  • 0≤P[i]<N0 \le P[i] < N for each 0≤i<N0 \le i < N
  • P[i]≠P[j]P[i] \ne P[j] for all 0≤i<j<N0 \le i < j < N

Examples1

  1. Example 1

    Input
    1
    3
    0 0 0
    0 1 2
    
    Expected output
    0 1 2