QOJ.ac

QOJ

حد الوقت: 1.0 s حد الذاكرة: 1024 MB مجموع النقاط: 100 الصعوبة: [عرض] قابلة للهجوم ✓

#14016. 相邻相加

الإحصائيات

小蓝鱼有一个由 $n$ 个整数组成的序列,记为 $a_1, a_2, \dots, a_n$。

对于给定的整数 $k \ge 2$,小蓝鱼可以进行任意次数(包括零次)的以下系列操作:

  • 首先,选择一个满足 $1 \le i \le n - 1$ 的整数 $i$,并选择一个整数 $x$($x$ 可以为负数)。
  • 然后,将 $a_i$ 加上 $x$,并将 $a_{i+1}$ 加上 $k \cdot x$。

小蓝鱼想知道,在进行任意次数的操作后,他是否能使 $a$ 的所有元素相等。

输入格式

每个输入文件包含多个测试用例。输入的第一行包含一个整数 $T$ ($T \ge 1$),表示测试用例的数量。对于每个测试用例:

第一行包含两个整数 $n$ 和 $k$ ($n \ge 2$, $2 \le k \le 10^9$)。

下一行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 10^9$)。

保证所有测试用例中 $n$ 的总和不超过 $5 \times 10^5$。

输出格式

对于每个测试用例,如果可以使 $a$ 的所有元素相等,则输出一行单个单词 “Yes”,否则输出 “No”。

样例

输入 1

3
3 2
9 4 2
2 4
4 7
5 3
40 63 64 96 1

输出 1

Yes
Yes
No

说明

对于第一个测试用例,你可以通过以下操作使 $a$ 的所有元素相等:

  • 选择 $i = 2, x = 4$。将 $a_2$ 加上 $4$,将 $a_3$ 加上 $8$。数组变为 $a = (9, 8, 10)$。
  • 选择 $i = 1, x = 1$。将 $a_1$ 加上 $1$,将 $a_2$ 加上 $2$。数组变为 $a = (10, 10, 10)$。

对于第二个测试用例,你可以通过以下操作使 $a$ 的所有元素相等:

  • 选择 $i = 1, x = -1$。将 $a_1$ 加上 $-1$,将 $a_2$ 加上 $-4$。数组变为 $a = (3, 3)$。

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.