CF1384B2-Koa and the Beach (Hard Version)
CF1384B2-Koa and the Beach (Hard Version)
题目:
题目描述:
The only difference between easy and hard versions is on constraints. In this version constraints are higher. You can make hacks only if all versions of the problem are solved.
Koa the Koala is at the beach!
The beach consists (from left to right) of a shore, meters of sea and an island at meters from the shore.
She measured the depth of the sea at meters from the shore and saved them in array . denotes the depth of the sea at meters from the shore for .
Like any beach this one has tide, the intensity of the tide is measured by parameter and affects all depths from the beginning at time in the following way:
- For a total of seconds, each second, tide increases all depths by .
- Then, for a total of seconds, each second, tide decreases all depths by .
- This process repeats again and again (ie. depths increase for seconds then decrease for seconds and so on …). Formally, let’s define -indexed array of length . At time ( ) depth at meters from the shore equals ( denotes the remainder of the division of by ). Note that the changes occur instantaneously after each second, see the notes for better understanding.
At time Koa is standing at the shore and wants to get to the island. Suppose that at some time ( ) she is at ( ) meters from the shore:
- In one second Koa can swim meter further from the shore ( changes to ) or not swim at all ( stays the same), in both cases changes to .
- As Koa is a bad swimmer, the depth of the sea at the point where she is can’t exceed at integer points of time (or she will drown). More formally, if Koa is at ( ) meters from the shore at the moment (for some integer ), the depth of the sea at this point — — can’t exceed . In other words, must hold always.
- Once Koa reaches the island at meters from the shore, she stops and can rest. Note that while Koa swims tide doesn’t have effect on her (ie. she can’t drown while swimming). Note that Koa can choose to stay on the shore for as long as she needs and neither the shore or the island are affected by the tide (they are solid ground and she won’t drown there).
Koa wants to know whether she can go from the shore to the island. Help her!
输入格式:
The first line of the input contains one integer ( ) — the number of test cases. Description of the test cases follows.
The first line of each test case contains three integers , and ( ) — the number of meters of sea Koa measured and parameters and .
The second line of each test case contains integers ( ) — the depths of each meter of sea Koa measured.
It is guaranteed that the sum of over all test cases does not exceed .
输出格式:
For each test case:
Print Yes if Koa can get from the shore to the island, and No otherwise.
You may print each letter in any case (upper or lower).
样例:
样例输入 1:
|
|
样例输出 1:
|
|
思路:
实现:
|
|
v1.4.14