CF1862B.Sequence Game
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Tema and Vika are playing the following game.
First, Vika comes up with a sequence of positive integers a of length m and writes it down on a piece of paper. Then she takes a new piece of paper and writes down the sequence b according to the following rule:
- First, she writes down a1.
- Then, she writes down only those ai (2≤i≤m) such that ai−1≤ai. Let the length of this sequence be denoted as n.
For example, from the sequence a=[4,3,2,6,3,3], Vika will obtain the sequence b=[4,6,3].
She then gives the piece of paper with the sequence b to Tema. He, in turn, tries to guess the sequence a.
Tema considers winning in such a game highly unlikely, but still wants to find at least one sequence a that could have been originally chosen by Vika. Help him and output any such sequence.
Note that the length of the sequence you output should not exceed the input sequence length by more than two times.
特玛和维卡正在玩以下游戏。
首先,维卡想出一个长度为 m 的正整数序列 a,并将其写在一张纸上。接着,她取一张新纸,按如下规则写出序列 b:
- 首先,她写下 a1;
- 然后,她仅写下那些满足 ai−1≤ai 的 ai(其中 2≤i≤m)。记该序列的长度为 n。
例如,对于序列 a=[4,3,2,6,3,3],维卡将得到序列 b=[4,6,3]。
随后,她将写有序列 b 的纸交给特玛。特玛则尝试猜测原始序列 a。
特玛认为在这种游戏中获胜的可能性极低,但仍希望至少找出一个可能由维卡最初选定的序列 a。请帮助他,并输出任意一个这样的序列。
注意:你所输出的序列长度不得超过输入序列长度的两倍。
输入格式
Each test consists of multiple test cases. The first line of input data contains a single integer t (1≤t≤104) — the number of test cases. This is followed by a description of the test cases.
The first line of each test case contains a single integer n (1≤n≤2⋅105) — the length of the sequence b.
The second line of each test case contains n integers b1,b2,b3,…,bn (1≤bi≤109) — the elements of the sequence.
The sum of the values of n over all test cases does not exceed 2⋅105.
每个测试包含多个测试用例。输入数据的第一行包含一个整数 t(1≤t≤104),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤2⋅105),表示序列 b 的长度。
每个测试用例的第二行包含 n 个整数 b1,b2,b3,…,bn(1≤bi≤109),表示该序列的元素。
所有测试用例中 n 的总和不超过 2⋅105。
输出格式
For each test case, output two lines. In the first line, output a single integer m — the length of the sequence (n≤m≤2⋅n). In the second line, output m integers a1,a2,a3,…,am (1≤ai≤109) — the assumed sequence that Vika could have written on the first piece of paper.
If there are multiple suitable sequences, you can output any of them.
对于每个测试用例,输出两行。第一行输出一个整数 m —— 序列的长度(满足 n≤m≤2⋅n)。第二行输出 m 个整数 a1,a2,a3,…,am(满足 1≤ai≤109)—— 即维卡可能写在第一张纸上的假设序列。
若存在多个符合条件的序列,你可以输出其中任意一个。
输入输出样例
输入#1
6 3 4 6 3 3 1 2 3 5 1 7 9 5 7 1 144 2 1 1 5 1 2 2 1 1
输出#1
6 4 3 2 6 3 3 3 1 2 3 6 1 7 9 3 5 7 1 144 2 1 1 6 1 2 2 1 1 1
说明/提示
The first sample is explained in the problem statement.
In the second sample, Vika could have chosen the original sequence.
第一个样例在题目描述中已作解释。
在第二个样例中,Vika 可以选择原始序列。
输入解题思路,AI测评打分。不知道怎么写?