CF1166D.Cute Sequences

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Given a positive integer mm, we say that a sequence x1,x2,…,xnx_1, x_2, \dots, x_n of positive integers is mm-cute if for every index ii such that 2≤i≤n2 \le i \le n it holds that xi=xi−1+xi−2+⋯+x1+rix_i = x_{i - 1} + x_{i - 2} + \dots + x_1 + r_i for some positive integer rir_i satisfying 1≤ri≤m1 \le r_i \le m.

You will be given qq queries consisting of three positive integers aa, bb and mm. For each query you must determine whether or not there exists an mm-cute sequence whose first term is aa and whose last term is bb. If such a sequence exists, you must additionally find an example of it.

给定一个正整数 mm,我们称一个正整数序列 x1,x2,…,xnx_1, x_2, \dots, x_n 是 mm-cute 的,如果对每个满足 2≤i≤n2 \le i \le n 的下标 ii,均存在某个满足 1≤ri≤m1 \le r_i \le m 的正整数 rir_i,使得

xi=xi−1+xi−2+⋯+x1+ri.x_i = x_{i - 1} + x_{i - 2} + \dots + x_1 + r_i.

你将收到 qq 个查询,每个查询包含三个正整数 aa、bb 和 mm。对每个查询,你必须判断:是否存在一个 mm-cute 序列,其首项为 aa、末项为 bb。若存在,你还须给出这样一个序列的一个具体例子。

输入格式

The first line contains an integer number qq (1≤q≤1031 \le q \le 10^3) — the number of queries.

Each of the following qq lines contains three integers aa, bb, and mm (1≤a,b,m≤10141 \le a, b, m \le 10^{14}, a≤ba \leq b), describing a single query.

第一行包含一个整数 qq(1≤q≤1031 \le q \le 10^3),表示查询次数。

接下来的 qq 行,每行包含三个整数 aa、bb 和 mm(1≤a,b,m≤10141 \le a, b, m \le 10^{14},且 a≤ba \leq b),描述一次查询。

输出格式

For each query, if no mm-cute sequence whose first term is aa and whose last term is bb exists, print −1-1.

Otherwise print an integer kk (1≤k≤501 \le k \leq 50), followed by kk integers x1,x2,…,xkx_1, x_2, \dots, x_k (1≤xi≤10141 \le x_i \le 10^{14}). These integers must satisfy x1=ax_1 = a, xk=bx_k = b, and that the sequence x1,x2,…,xkx_1, x_2, \dots, x_k is mm-cute.

It can be shown that under the problem constraints, for each query either no mm-cute sequence exists, or there exists one with at most 5050 terms.

If there are multiple possible sequences, you may print any of them.

对于每个查询,如果不存在首项为 aa、末项为 bb 的 mm-cute 序列,则输出 −1-1。

否则,先输出一个整数 kk(1≤k≤501 \le k \leq 50),再输出 kk 个整数 x1,x2,…,xkx_1, x_2, \dots, x_k(1≤xi≤10141 \le x_i \le 10^{14})。这些整数必须满足 x1=ax_1 = a、xk=bx_k = b,且序列 x1,x2,…,xkx_1, x_2, \dots, x_k 是 mm-cute 的。

可以证明,在本题的约束条件下,对每个查询,要么不存在 mm-cute 序列,要么存在一个长度至多为 5050 的 mm-cute 序列。

若存在多个可能的序列,输出任意一个即可。

输入输出样例

  • 输入#1

    2
    5 26 2
    3 9 1

    输出#1

    4 5 6 13 26
    -1

说明/提示

Consider the sample. In the first query, the sequence 5,6,13,265, 6, 13, 26 is valid since 6=5+16 = 5 + \bf{\color{blue} 1}, 13=6+5+213 = 6 + 5 + {\bf\color{blue} 2} and 26=13+6+5+226 = 13 + 6 + 5 + {\bf\color{blue} 2} have the bold values all between 11 and 22, so the sequence is 22-cute. Other valid sequences, such as 5,7,13,265, 7, 13, 26 are also accepted.

In the second query, the only possible 11-cute sequence starting at 33 is 3,4,8,16,…3, 4, 8, 16, \dots, which does not contain 99.

考虑样例。在第一个查询中,序列 5,6,13,265, 6, 13, 26 是合法的,因为 6=5+16 = 5 + \bf{\color{blue} 1}、13=6+5+213 = 6 + 5 + {\bf\color{blue} 2} 且 26=13+6+5+226 = 13 + 6 + 5 + {\bf\color{blue} 2},其中加粗的值均介于 11 和 22 之间,因此该序列是 22-cute 的。其他合法序列(例如 5,7,13,265, 7, 13, 26)也同样被接受。

在第二个查询中,唯一可能的以 33 开头的 11-cute 序列为 3,4,8,16,…3, 4, 8, 16, \dots,该序列不包含 99。

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

首页