QOJ.ac

QOJ

时间限制: 2.0 s 内存限制: 1024 MB 总分: 100 可 Hack ✓

#18125. 无聊的构造题

统计

世界上最无聊的构造题是读入 $n, m$ 并输出一个满足条件 1,2,3,4,5,6,7,8 的矩阵。

给定四个整数 $a, b, n, s$ ($a \neq b$)。你需要构造一个长度为 $n$ 的序列 $c$,满足:

  • 对于每个 $1 \le i \le n$,$c_i \in \{a, b\}$;
  • 不存在一个连续子数组 $c_l, c_{l+1}, \dots, c_r$,其和恰好为 $s$。

更正式地,不存在满足 $1 \le l \le r \le n$ 的整数对 $(l, r)$ 使得 $c_l + c_{l+1} + \dots + c_r = s$。

对于每个测试用例,判断是否存在这样一个序列:

  • 如果存在,输出 YES,并输出任意一个合法的序列;
  • 否则,输出 NO

输入格式

第一行包含一个整数 $T$ ($1 \le T \le 10^5$),表示测试用例的数量。

接下来的 $T$ 行,每行包含四个整数 $a, b, n, s$ ($1 \le a, b, s \le 10^9$,$1 \le n \le 5 \cdot 10^5$,$a \neq b$)。

保证所有 $n$ 的总和不超过 $5 \cdot 10^5$。

输出格式

对于每个测试用例:

  • 如果无解,输出一行包含 NO
  • 如果有解,首先输出一行包含 YES,然后输出一行包含 $n$ 个整数,表示你构造的序列。

如果存在多个合法答案,输出其中任意一个。

样例

输入样例 1

3
2 4 6 8
2 5 5 9
3 4 3 7

输出样例 1

NO
YES
2 5 5 5 2
YES
4 4 4

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.