knightnemo commited on
Commit
a3d0aa3
·
verified ·
1 Parent(s): 0f19b3f

Upload code_segments/segment_144.txt with huggingface_hub

Browse files
Files changed (1) hide show
  1. code_segments/segment_144.txt +27 -0
code_segments/segment_144.txt ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ You are given an array $b$ of $n - 1$ integers.
2
+
3
+ An array $a$ of $n$ integers is called good if $b_i = a_i \, \& \, a_{i + 1}$ for $1 \le i \le n-1$, where $\&$ denotes the [bitwise AND operator](https://en.wikipedia.org/wiki/Bitwise_operation#AND).
4
+
5
+ Construct a good array, or report that no good arrays exist.
6
+
7
+ Each test contains multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases. The description of test cases follows.
8
+
9
+ The first line of each test case contains a single integer $n$ ($2 \le n \le 10^5$) — the length of the array $a$.
10
+
11
+ The second line of each test case contains $n - 1$ integers $b_1, b_2, \ldots, b_{n - 1}$ ($0 \le b_i < 2^{30}$) — the elements of the array $b$.
12
+
13
+ It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
14
+
15
+ For each test case, output a single integer $-1$ if no good arrays exist.
16
+
17
+ Otherwise, output $n$ space-separated integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i < 2^{30}$) — the elements of a good array $a$.
18
+
19
+ If there are multiple solutions, you may output any of them.
20
+
21
+ In the first test case, $b = [1]$. A possible good array is $a=[5, 3]$, because $a_1 \, \& \, a_2 = 5 \, \& \, 3 = 1 = b_1$.
22
+
23
+ In the second test case, $b = [2, 0]$. A possible good array is $a=[3, 2, 1]$, because $a_1 \, \& \, a_2 = 3 \, \& \, 2 = 2 = b_1$ and $a_2 \, \& \, a_3 = 2 \, \& \, 1 = 0 = b_2$.
24
+
25
+ In the third test case, $b = [1, 2, 3]$. It can be shown that no good arrays exist, so the output is $-1$.
26
+
27
+ In the fourth test case, $b = [3, 5, 4, 2]$. A possible good array is $a=[3, 7, 5, 6, 3]$.