310175: CF1793B. Fedya and Array

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

Description

Fedya and Array

题意翻译

有一个 $n$ 个元素的序列 $a$,元素首尾相连排成圆环,任意两个相邻元素间差的绝对值等于 $1$。定义一个局部最小值为**同时**小于左右两个相邻元素的元素值,一个局部最大值为**同时**大于左右两个相邻元素的元素值。 **注意,元素 $a_n$ 和 元素 $a_1$ 是相邻元素。** 给定序列 $a$ 中**所有**局部最大值的和以及序列 $a$ 中**所有**局部最小值的和,请还原出**元素个数最少**的数组 $a$。

题目描述

For his birthday recently Fedya was given an array $ a $ of $ n $ integers arranged in a circle, For each pair of neighboring numbers ( $ a_1 $ and $ a_2 $ , $ a_2 $ and $ a_3 $ , $ \ldots $ , $ a_{n - 1} $ and $ a_n $ , $ a_n $ and $ a_1 $ ) the absolute difference between them is equal to $ 1 $ . Let's call a local maximum an element, which is greater than both of its neighboring elements. Also call a local minimum an element, which is less than both of its neighboring elements. Note, that elements $ a_1 $ and $ a_n $ are neighboring elements. Unfortunately, Fedya lost an array, but he remembered in it the sum of local maximums $ x $ and the sum of local minimums $ y $ . Given $ x $ and $ y $ , help Fedya find any matching array of minimum length.

输入输出格式

输入格式


Each test contains multiple test cases. The first line contains the number of test cases $ t $ ( $ 1 \le t \le 1000 $ ). Description of the test cases follows. Each line of each test case contain two integers $ x $ and $ y $ ( $ -10^{9} \le y < x \le 10^{9} $ ) — the sum of local maximums and the sum of local minimums, respectively.

输出格式


For each test case, in the first line print one integer $ n $ — the minimum length of matching arrays. In the second line print $ n $ integers $ a_1, a_2, \ldots, a_n $ ( $ -10^{9} \leqslant a_i \leqslant 10^{9} $ ) — the array elements such that the the absolute difference between each pair of neighboring is equal to $ 1 $ . If there are multiple solutions, print any of them. It is guaranteed that the sum of $ n $ over all test cases does not exceed $ 2 \cdot 10^{5} $ .

输入输出样例

输入样例 #1

4
3 -2
4 -4
2 -1
5 -3

输出样例 #1

10
0 1 2 1 0 -1 0 -1 0 1
16
-2 -1 -2 -1 0 1 2 3 4 5 4 3 2 1 0 -1 
6
1 0 -1 0 1 0
16
2 3 2 1 0 -1 0 -1 0 -1 0 1 2 1 0 1

说明

In the first test case, the local maximums are the numbers at $ 3, 7 $ and $ 10 $ positions, and the local minimums are the numbers at $ 1, 6 $ and $ 8 $ positions. $ x = a_3 + a_7 + a_{10} = 2 + 0 + 1 = 3 $ , $ y = a_1 + a_6 + a_8 = 0 + (-1) + (-1) = -2 $ . In the second test case, the local maximums are the numbers at $ 2 $ and $ 10 $ positions, and the local minimums are the numbers at $ 1 $ and $ 3 $ positions. $ x = a_2 + a_{10} = -1 + 5 = 4 $ , $ y = a_1 + a_3 = -2 + (-2) = -4 $ . In the third test case, the local maximums are the numbers at $ 1 $ and $ 5 $ positions, and the local minimums are the numbers at $ 3 $ and $ 6 $ positions.

Input

题意翻译

有一个 $n$ 个元素的序列 $a$,元素首尾相连排成圆环,任意两个相邻元素间差的绝对值等于 $1$。定义一个局部最小值为**同时**小于左右两个相邻元素的元素值,一个局部最大值为**同时**大于左右两个相邻元素的元素值。 **注意,元素 $a_n$ 和 元素 $a_1$ 是相邻元素。** 给定序列 $a$ 中**所有**局部最大值的和以及序列 $a$ 中**所有**局部最小值的和,请还原出**元素个数最少**的数组 $a$。

Output

**费佳和数组**

**题意翻译**

给定一个由n个整数组成的序列a,这些整数首尾相连形成一个圆环,圆环中任意两个相邻元素的差的绝对值等于1。定义一个局部最小值为同时小于其左右两个相邻元素的元素值,一个局部最大值为同时大于其左右两个相邻元素的元素值。

**注意,元素a_n和元素a_1是相邻元素。**

给定序列a中所有局部最大值的和以及序列a中所有局部最小值的和,请还原出元素个数最少的数组a。

**题目描述**

费佳(Fedya)最近过生日时收到了一个由n个整数组成的数组a,这些整数首尾相连形成一个圆环,圆环中任意两个相邻元素的差的绝对值等于1。

我们将一个局部最大值定义为一个大于其两个相邻元素的元素。同样,将一个局部最小值定义为一个小于其两个相邻元素的元素。注意,元素a_1和元素a_n是相邻元素。

不幸的是,费佳丢失了这个数组,但他记得数组中所有局部最大值的和为x,所有局部最小值的和为y。

给定x和y,请帮助费佳找到任意一个符合条件的数组a,并使其长度最小。

**输入输出格式**

**输入格式**

每个测试用例包含多个测试案例。第一行包含测试案例的数量t(1≤t≤1000)。接下来是每个测试案例的描述。

每个测试案例的每一行包含两个整数x和y(-10^9≤y
**输出格式**

对于每个测试案例,第一行输出一个整数n——匹配数组的最小长度。

在第二行输出n个整数a_1, a_2, …, a_n(-10^9≤a_i≤10^9)——数组的元素,使得任意两个相邻元素的差的绝对值等于1。

如果有多个解决方案,请输出其中任意一个。

保证所有测试案例的n之和不超过2×10^5。

**输入输出样例**

**输入样例 #1**

```
4
3 -2
4 -4
2 -1
5 -3
```

**输出样例 #1**

```
10
0 1 2 1 0 -1 0 -1 0 1
16
-2 -1 -2 -1 0 1 2 3 4 5 4 3 2 1 0 -1
6
1 0 -1 0 1 0
16
2 3 2 1 0 -1 0 -1 0 -1 0 1 2 1 0 1
```

**说明**

在第一个测试案例中,局部最大值位于第3、7和10的位置,局部最小值位于第1、6和8的位置。x = a_3 + a_7 + a_10 = 2 + 0 + 1 = 3,y = a_1 + a_6 + a_8 = 0 + (-1) + (-1) = -2。

在第二个测试案例中,局部最大值位于第2和第10的位置,局部最小值位于第1和第3的位置。x = a_2 + a_10 = -1 + 5 = 4,y = a_1 + a_3 = -2 + (-2) = -4。

在第三个测试案例中,局部最大值位于第1和第5的位置,局部最小值位于第3和第6的位置。**费佳和数组** **题意翻译** 给定一个由n个整数组成的序列a,这些整数首尾相连形成一个圆环,圆环中任意两个相邻元素的差的绝对值等于1。定义一个局部最小值为同时小于其左右两个相邻元素的元素值,一个局部最大值为同时大于其左右两个相邻元素的元素值。 **注意,元素a_n和元素a_1是相邻元素。** 给定序列a中所有局部最大值的和以及序列a中所有局部最小值的和,请还原出元素个数最少的数组a。 **题目描述** 费佳(Fedya)最近过生日时收到了一个由n个整数组成的数组a,这些整数首尾相连形成一个圆环,圆环中任意两个相邻元素的差的绝对值等于1。 我们将一个局部最大值定义为一个大于其两个相邻元素的元素。同样,将一个局部最小值定义为一个小于其两个相邻元素的元素。注意,元素a_1和元素a_n是相邻元素。 不幸的是,费佳丢失了这个数组,但他记得数组中所有局部最大值的和为x,所有局部最小值的和为y。 给定x和y,请帮助费佳找到任意一个符合条件的数组a,并使其长度最小。 **输入输出格式** **输入格式** 每个测试用例包含多个测试案例。第一行包含测试案例的数量t(1≤t≤1000)。接下来是每个测试案例的描述。 每个测试案例的每一行包含两个整数x和y(-10^9≤y

加入题单

算法标签: