QOJ.ac

QOJ

Time Limit: 2.0 s Memory Limit: 1024 MB Total points: 100 Hackable ✓

#18125. 無聊構造題

Statistics

題目描述

世界上最無聊嘅構造題係讀入 $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.