CF1793B.Fedya and Array

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

For his birthday recently Fedya was given an array aa of nn integers arranged in a circle, For each pair of neighboring numbers (a1a_1 and a2a_2, a2a_2 and a3a_3, …\ldots, an−1a_{n - 1} and ana_n, ana_n and a1a_1) the absolute difference between them is equal to 11.

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 a1a_1 and ana_n are neighboring elements.

Unfortunately, Fedya lost an array, but he remembered in it the sum of local maximums xx and the sum of local minimums yy.

Given xx and yy, help Fedya find any matching array of minimum length.

最近,费佳生日时收到了一个由 nn 个整数组成的环形数组 aa。对于每一对相邻元素(即 a1a_1 与 a2a_2、a2a_2 与 a3a_3、…\ldots、an−1a_{n - 1} 与 ana_n、ana_n 与 a1a_1),它们的绝对差值均为 11。

我们称一个局部最大值为严格大于其两个相邻元素的元素;类似地,称一个局部最小值为严格小于其两个相邻元素的元素。注意:a1a_1 和 ana_n 是相邻元素。

不幸的是,费佳丢失了该数组,但他记得数组中所有局部最大值之和为 xx,所有局部最小值之和为 yy。

给定 xx 和 yy,请帮助费佳构造出任意一个满足条件且长度最短的数组。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤10001 \le t \le 1000). Description of the test cases follows.

Each line of each test case contain two integers xx and yy (−109≤y<x≤109-10^{9} \le y \lt x \le 10^{9}) — the sum of local maximums and the sum of local minimums, respectively.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤10001 \le t \le 1000)。随后是各测试用例的描述。

每个测试用例的每一行包含两个整数 xx 和 yy(−109≤y<x≤109-10^{9} \le y \lt x \le 10^{9}),分别表示局部最大值之和与局部最小值之和。

输出格式

For each test case, in the first line print one integer nn — the minimum length of matching arrays.

In the second line print nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (−109⩽ai⩽109-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 11.

If there are multiple solutions, print any of them.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^{5}.

对于每个测试用例,在第一行输出一个整数 nn —— 满足条件的数组的最小长度。

在第二行输出 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(其中 −109⩽ai⩽109-10^{9} \leqslant a_i \leqslant 10^{9})—— 表示该数组的元素,使得每一对相邻元素的绝对差值均为 11。

若存在多种解,输出任意一种即可。

保证所有测试用例的 nn 值之和不超过 2⋅1052 \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,73, 7 and 1010 positions, and the local minimums are the numbers at 1,61, 6 and 88 positions. x=a3+a7+a10=2+0+1=3x = a_3 + a_7 + a_{10} = 2 + 0 + 1 = 3, y=a1+a6+a8=0+(−1)+(−1)=−2y = a_1 + a_6 + a_8 = 0 + (-1) + (-1) = -2.

In the second test case, the local maximums are the numbers at 22 and 1010 positions, and the local minimums are the numbers at 11 and 33 positions. x=a2+a10=−1+5=4x = a_2 + a_{10} = -1 + 5 = 4, y=a1+a3=−2+(−2)=−4y = a_1 + a_3 = -2 + (-2) = -4.

In the third test case, the local maximums are the numbers at 11 and 55 positions, and the local minimums are the numbers at 33 and 66 positions.

在第一个测试用例中,局部最大值位于位置 33、77 和 1010 处的数字,局部最小值位于位置 11、66 和 88 处的数字。x=a3+a7+a10=2+0+1=3x = a_3 + a_7 + a_{10} = 2 + 0 + 1 = 3,y=a1+a6+a8=0+(−1)+(−1)=−2y = a_1 + a_6 + a_8 = 0 + (-1) + (-1) = -2。

在第二个测试用例中,局部最大值位于位置 22 和 1010 处的数字,局部最小值位于位置 11 和 33 处的数字。x=a2+a10=−1+5=4x = a_2 + a_{10} = -1 + 5 = 4,y=a1+a3=−2+(−2)=−4y = a_1 + a_3 = -2 + (-2) = -4。

在第三个测试用例中,局部最大值位于位置 11 和 55 处的数字,局部最小值位于位置 33 和 66 处的数字。

输入解题思路,AI测评打分。不知道怎么写?

首页