#P8942. Deadly Mutated Sequence
Deadly Mutated Sequence
Deadly Mutated Sequence
Susan and Baker are racing against time to crack the password to shut down a worm virus. They discovered that the password is a sequence of n positive integers, each in the range [1, m], which is non‐decreasing. In addition, if we define the prefix XOR sums by
$$p_i=a_1\oplus a_2\oplus\cdots\oplus a_i,\;\;\; (1\le i\le n),$$then the sequence of prefix XOR sums must be non‐decreasing, i.e.
$$p_{i-1}\le p_i\quad\text{for }2\le i\le n.$$Similarly, if we define the suffix XOR sums by
$$s_i=a_n\oplus a_{n-1}\oplus\cdots\oplus a_i,\;\;\; (1\le i\le n),$$then they should also be non‐decreasing (when read in the natural order):
$$s_{i}\le s_{i-1}\quad\text{for }2\le i\le n.$$Your task is to construct any sequence \(a_1, a_2, \ldots, a_n\) with all elements in [1, m] which is non‐decreasing and satisfies both of the above XOR conditions. If no such sequence exists, output -1
.
Observation: One valid construction is to let \(a_i=2^{i-1}\) for \(i=1,2,\ldots,n\). In this case, the prefix XOR sums become \(p_i=2^i-1\) which is strictly increasing. It can be verified that the suffix XOR sums are also non‐decreasing. Hence, a valid solution exists provided that \(2^{n-1}\le m\>.
inputFormat
The first line contains an integer \(T\) (\(T \ge 1\)), the number of test cases. Then \(T\) test cases follow.
Each test case consists of a single line containing two integers \(n\) and \(m\) (\(1 \le n \le 10^5\), \(1 \le m \le 10^9\)).
outputFormat
For each test case, if there exists a valid sequence, output \(n\) space-separated integers representing the sequence. Otherwise, output -1
.
sample
4
1 1
2 2
3 4
3 3
1
1 2
1 2 4
-1
</p>