CF2247B.Yet Another Constructive

入门

通过率:0%

时间限制:1.50s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given three integers nn, kk, and mm.

We call an array aa of length nn, consisting of positive integers, good if the minimum length of a non-empty subarray∗^{\text{∗}} of aa whose sum is divisible by mm equals kk.

Formally, an array aa is good if the following conditions hold:

  • there exist integers ll and rr such that 1≤l≤r≤n1 \le l \le r \le n, r−l+1=kr - l + 1 = k, and ∑i=lrai\sum\limits_{i = l}^{r} a_i is divisible by mm;
  • there do not exist integers ll and rr such that 1≤l≤r≤n1 \le l \le r \le n, r−l+1<kr - l + 1 \lt k, and ∑i=lrai\sum\limits_{i = l}^{r} a_i is divisible by mm.

Find any good array aa, or determine that no such array exists.

∗^{\text{∗}}An array aa is a subarray of an array bb if aa can be obtained from bb by the deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

给你三个整数 nn、kk 和 mm。

我们称一个长度为 nn、由正整数组成的数组 aa 是好数组,当且仅当:其所有非空子数组中,和能被 mm 整除的最短子数组的长度恰好等于 kk。

形式化地,数组 aa 是好数组当且仅当满足以下两个条件:

  • 存在整数 ll 和 rr,使得 1≤l≤r≤n1 \le l \le r \le n,r−l+1=kr - l + 1 = k,且 ∑i=lrai\sum\limits_{i = l}^{r} a_i 能被 mm 整除;
  • 不存在整数 ll 和 rr,使得 1≤l≤r≤n1 \le l \le r \le n,r−l+1<kr - l + 1 \lt k,且 ∑i=lrai\sum\limits_{i = l}^{r} a_i 能被 mm 整除。

请构造任意一个好数组 aa,或判断不存在这样的数组。

∗^{\text{∗}} 若数组 aa 可通过从数组 bb 的开头删除若干(可能为零个或全部)元素,并从结尾删除若干(可能为零个或全部)元素而得到,则称 aa 是 bb 的一个子数组。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The only line of each test case contains three integers nn, kk, and mm (1≤k≤n≤2⋅1051 \le k \le n \le 2 \cdot 10^5, 1≤m≤1091 \le m \le 10^9).

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

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

每个测试用例仅有一行,包含三个整数 nn、kk 和 mm(1≤k≤n≤2⋅1051 \le k \le n \le 2 \cdot 10^5,1≤m≤1091 \le m \le 10^9)。

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, if an answer exists, output "YES" on the first line. On the second line, output nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤10181 \le a_i \le 10^{18}) — the array aa satisfying the conditions of the problem. If there are multiple valid solutions, output any of them.

Otherwise, output a single line containing "NO".

You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

对于每个测试用例,如果存在答案,则在第一行输出 “YES”。在第二行输出 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤10181 \le a_i \le 10^{18})——即满足题目条件的数组 aa。若存在多个合法解,输出任意一个即可。

否则,输出一行,内容为 “NO”。

你可以以任意大小写形式输出答案(例如字符串 “yEs”、“yes”、“Yes” 和 “YES” 均会被识别为肯定回答)。

输入输出样例

  • 输入#1

    4
    1 1 1
    5 3 5
    2 2 1000000000
    6 4 3

    输出#1

    YES
    1
    YES
    9 17 14 23 11
    YES
    500000000 500000000
    NO

说明/提示

In the first example, one possible solution is a=[1]a = [1]. The only non-empty subarray has length k=1k = 1, and its sum is divisible by m=1m = 1.

In the second example, one possible solution is a=[9,17,14,23,11]a = [9, 17, 14, 23, 11]. The sum of the subarray [9,17,14][9, 17, 14] is 9+17+14=409 + 17 + 14 = 40, which is divisible by m=5m = 5. It can be shown that no non-empty subarray with fewer than k=3k = 3 elements has a sum divisible by 55, so this solution is valid.

In the fourth example, it can be shown that no good array aa exists.

在第一个例子中,一个可能的解是 a=[1]a = [1]。唯一的非空子数组长度为 k=1k = 1,其和可被 m=1m = 1 整除。

在第二个例子中,一个可能的解是 a=[9,17,14,23,11]a = [9, 17, 14, 23, 11]。子数组 [9,17,14][9, 17, 14] 的和为 9+17+14=409 + 17 + 14 = 40,可被 m=5m = 5 整除。可以证明:不存在长度少于 k=3k = 3 的非空子数组,其和能被 55 整除,因此该解有效。

在第四个例子中,可以证明不存在满足条件的好数组 aa。

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

首页