Codeforces Round 1093 (Div. 2)
B
OIE Excursion
Codeforces
1200
原题
← AC →
翻译中…

Hector is on an excursion with the Spanish Olympiad in Informatics, visiting A Coruña, but he is desperate to sneak away to meet his friends Gustavo, Esomer, and Dani. To do so, he must cross a path guarded by $n$ volunteers standing in a row, numbered from $1$ to $n$; the $i$-th volunteer watches over position $i$.

翻译中…

Each volunteer has an internal timer. Initially (at second $0$), the $i$-th volunteer's timer has a value $a_i$. Every second, all timers increase by $1$. Once a timer reaches $m$, it wraps around to $0$. Specifically, at second $x$, the $i$-th volunteer's timer shows the value $(a_i + x) \pmod m$.

翻译中…

The $i$-th volunteer is only watching over position $i$ when their timer is exactly $0$. At any other time, they are distracted and will not notice Hector.

翻译中…

Hector starts at position $0$, to the left of all volunteers. To escape, he must reach position $n+1$. In the end of each second, Hector can choose to stay in his current position, move one position to the left, or move one position to the right. Note that Hector can't go to the left of position $0$.

翻译中…

Hector is caught if and only if, at the beginning of a second, he is at position $i$ ($1 \le i \le n$) and the $i$-th volunteer's timer is $0$.

翻译中…

Determine whether there exists a strategy for Hector to pass all volunteers and escape without being caught.

翻译中…

Input

翻译中…

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

翻译中…

Each test case consists of two lines:

翻译中…
  • The first line contains two integers $n$ and $m$ ($2 \le n \le 2 \cdot 10^5$, $2 \le m \le 10^9$) — the number of volunteers and the cycle length of the timers.
  • The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \lt m$), where $a_i$ represents the initial value of the $i$-th volunteer's timer at $t=0$.
翻译中…

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

翻译中…

Output

翻译中…

For each test case, print a line containing either "YES" or "NO", representing whether Hector can escape. 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.

翻译中…

Note

翻译中…
  • Case 1: Hector can move right every second without waiting or moving left and escape, because there is no $i$ such that $(a_i + i) \pmod m = 0$.
  • Case 2: One possible strategy is to wait for one second at the starting position and then move right every second without further waiting or moving left.
翻译中…

样例

Input #1
6
8 5
0 4 0 2 1 0 0 3
6 2
1 0 1 0 1 0
6 2
1 1 1 1 0 1
2 10
6 9
2 2
0 1
5 1000000000
1 2 3 4 999999999
Output #1
YES
YES
NO
YES
YES
YES
InputCopy OutputCopy
题目信息
题号
2220B
时间限制
1 s
内存限制
256 MB
标签
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。