310296: CF1811C. Restore the Array

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C. Restore the Arraytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Kristina had an array $a$ of length $n$ consisting of non-negative integers.

She built a new array $b$ of length $n-1$, such that $b_i = \max(a_i, a_{i+1})$ ($1 \le i \le n-1$).

For example, suppose Kristina had an array $a$ = [$3, 0, 4, 0, 5$] of length $5$. Then she did the following:

  1. Calculated $b_1 = \max(a_1, a_2) = \max(3, 0) = 3$;
  2. Calculated $b_2 = \max(a_2, a_3) = \max(0, 4) = 4$;
  3. Calculated $b_3 = \max(a_3, a_4) = \max(4, 0) = 4$;
  4. Calculated $b_4 = \max(a_4, a_5) = \max(0, 5) = 5$.
As a result, she got an array $b$ = [$3, 4, 4, 5$] of length $4$.

You only know the array $b$. Find any matching array $a$ that Kristina may have originally had.

Input

The first line of input data contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases.

The description of the test cases follows.

The first line of each test case contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) — the number of elements in the array $a$ that Kristina originally had.

The second line of each test case contains exactly $n-1$ non-negative integer — elements of array $b$ ($0 \le b_i \le 10^9$).

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$, and that array $b$ was built correctly from some array $a$.

Output

For each test case on a separate line, print exactly $n$ non-negative integers — the elements of the array $a$ that Kristina originally had.

If there are several possible answers — output any of them.

ExampleInput
11
5
3 4 4 5
4
2 2 1
5
0 0 0 0
6
0 3 4 4 3
2
10
4
3 3 3
5
4 2 5 5
4
3 3 3
4
2 1 0
3
4 4
6
8 1 3 5 10
Output
3 0 4 0 5
2 2 1 1
0 0 0 0 0
0 0 3 4 3 3
10 10
3 3 3 1
4 2 2 5 5
3 3 3 3
2 1 0 0
2 4 4
8 1 1 3 5 10
Note

The first test case is explained in the problem statement.

In the second test case, we can get array $b$ = [$2, 2, 1$] from the array $a$ = [$2, 2, 1, 1$]:

  • $b_1 = \max(a_1, a_2) = \max(2, 2) = 2$;
  • $b_2 = \max(a_2, a_3) = \max(2, 1) = 2$;
  • $b_3 = \max(a_3, a_4) = \max(1, 1) = 1$.

In the third test case, all elements of the array $b$ are zeros. Since each $b_i$ is the maximum of two adjacent elements of array $a$, array $a$ can only consist entirely of zeros.

In the fourth test case, we can get array $b$ = [$0, 3, 4, 4, 3$] from the array $a$ = [$0, 0, 3, 4, 3, 3$] :

  • $b_1 = \max(a_1, a_2) = \max(0, 0) = 0$;
  • $b_2 = \max(a_2, a_3) = \max(0, 3) = 3$;
  • $b_3 = \max(a_3, a_4) = \max(3, 4) = 4$;
  • $b_4 = \max(a_4, a_5) = \max(4, 3) = 4$;
  • $b_5 = \max(a_5, a_6) = \max(3, 3) = 3$.

Input

题意翻译

### 题目描述 Kristina 有一个包含 $ n $ 个**非负整数**的数组 $ a $。 她构造了一个长度为 $ n - 1 $ 的新数组 $ b $,使得 $ b_i = \max(a_i, a_{i + 1}) \text{ } (1 \le i \le n - 1) $。 例如,假设 Kristina 有一个长度为 $ 5 $ 的数组 $ a = [ 3, 0, 4, 0, 5 ] $,则她将以以下方式构造数组 $ b $: 1. $ b_1 = \max(a_1, a_2) = \max(3, 0) = 3; $ 2. $ b_2 = \max(a_2, a_3) = \max(0, 4) = 4; $ 3. $ b_3 = \max(a_3, a_4) = \max(4, 0) = 4; $ 4. $ b_4 = \max(a_4, a_5) = \max(0, 5) = 5. $ 所以,她得到了一个长度为 $ 4 $ 的数组 $ b = [ 3, 4, 4, 5 ] $。 现在,你只知道数组 $ b $。你需要找出**任意一个**可能的数组 $ a $。 ### 输入格式 输入数据的第一行包含一个整数 $ t \text{ } (1 \le t \le 10 ^ 4) $,代表测试数据组数。 每组测试数据的第一行包含一个整数 $ n \text{ } (1 \le n \le 2 \times 10 ^ 5) $,代表数组 $ a $ 的长度。 每组测试数据的第二行包含 $ n - 1 $ 个非负整数,代表数组 $ b $ 的各个元素 $ (0 \le b_i \le 10^9) $。 对于每个测试点,保证所有 $ t $ 组测试数据中 $ n $ 的总和不超过 $ 2 \times 10 ^ 5 $,且保证有解。 ### 输出格式 对于每组测试数据,在同一行内输出 $ n $ 个非负整数,代表数组 $ a $ 的元素,元素与元素之间以空格隔开。 如果有多种可能的答案,输出**任意一种**即可。 ### 说明/提示 样例中的第一组测试数据已在题目描述中解释。 对于第二组测试数据,我们可以从 $ a = [ 2, 2, 1, 1 ] $ 推出 $ b = [ 2, 2, 1 ] $: * $ b_1 = \max(a_1, a_2) = \max(2, 2) = 2; $ * $ b_2 = \max(a_2, a_3) = \max(2, 1) = 2; $ * $ b_3 = \max(a_3, a_4) = \max(1, 1) = 1. $ 对于第三组测试数据,数组 $ b $ 中的所有元素均为 $ 0 $,因为 $ b $ 中的每个元素均为 $ a $ 中两个相邻元素的最大值,所以数组 $ a $ 中的每个元素均为 $ 0 $。 对于第四组测试数据,我们可以从 $ a = [ 0, 0, 3, 4, 3, 3 ] $ 推出 $ b = [ 0, 3, 4, 3, 3 ] $: * $ b_1 = \max(a_1, a_2) = \max(0, 0) = 0; $ * $ b_2 = \max(a_2, a_3) = \max(0, 3) = 3; $ * $ b_3 = \max(a_3, a_4) = \max(3, 4) = 4; $ * $ b_4 = \max(a_4, a_5) = \max(4, 3) = 4; $ * $ b_5 = \max(a_5, a_6) = \max(3, 3) = 3. $

Output

题目大意:
克里斯蒂娜有一个由非负整数组成的长度为n的数组a。她构建了一个新数组b,长度为n-1,使得b_i = max(a_i, a_{i+1}) (1 ≤ i ≤ n-1)。现在给出数组b,需要找到可能的原始数组a。

输入输出数据格式:
输入:
- 第一行包含一个整数t(1 ≤ t ≤ 10^4),表示测试用例的数量。
- 每个测试用例的描述如下:
- 第一行包含一个整数n(2 ≤ n ≤ 2 × 10^5),表示克里斯蒂娜原始数组a的元素数量。
- 第二行包含n-1个非负整数,表示数组b的元素(0 ≤ b_i ≤ 10^9)。

输出:
- 对于每个测试用例,输出一行,包含n个非负整数,表示克里斯蒂娜原始数组a的元素。
- 如果有多个可能的答案,输出其中任意一个。题目大意: 克里斯蒂娜有一个由非负整数组成的长度为n的数组a。她构建了一个新数组b,长度为n-1,使得b_i = max(a_i, a_{i+1}) (1 ≤ i ≤ n-1)。现在给出数组b,需要找到可能的原始数组a。 输入输出数据格式: 输入: - 第一行包含一个整数t(1 ≤ t ≤ 10^4),表示测试用例的数量。 - 每个测试用例的描述如下: - 第一行包含一个整数n(2 ≤ n ≤ 2 × 10^5),表示克里斯蒂娜原始数组a的元素数量。 - 第二行包含n-1个非负整数,表示数组b的元素(0 ≤ b_i ≤ 10^9)。 输出: - 对于每个测试用例,输出一行,包含n个非负整数,表示克里斯蒂娜原始数组a的元素。 - 如果有多个可能的答案,输出其中任意一个。

加入题单

算法标签: