CF346E.Doodle Jump

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

In Doodle Jump the aim is to guide a four-legged creature called "The Doodler" up a never-ending series of platforms without falling. — Wikipedia.

It is a very popular game and xiaodao likes it very much. One day when playing the game she wondered whether there exists a platform that the doodler couldn't reach due to the limits of its jumping ability. Consider the following problem.

There are n platforms. The height of the x-th (1 ≤ x ≤ n) platform is a·x mod p, where a and p are positive co-prime integers. The maximum possible height of a Doodler's jump is h. That is, it can jump from height _h_1 to height _h_2 (_h_1 < _h_2) if _h_2 - _h_1 ≤ h. Initially, the Doodler is on the ground, the height of which is 0. The question is whether it can reach the highest platform or not.

For example, when a = 7, n = 4, p = 12, h = 2, the heights of the platforms are 7, 2, 9, 4 as in the picture below. With the first jump the Doodler can jump to the platform at height 2, with the second one the Doodler can jump to the platform at height 4, but then it can't jump to any of the higher platforms. So, it can't reach the highest platform.

User xiaodao thought about the problem for a long time but didn't solve it, so she asks you for help. Also, she has a lot of instances of the problem. Your task is solve all of these instances.

在《涂鸦跳跃》(Doodle Jump)中,玩家的目标是引导一个名为“涂鸦者”(The Doodler)的四足生物,在一系列永无止境的平台间不断向上跳跃,且不能坠落。——维基百科。

这是一款非常流行的游戏,小道非常喜欢它。某天,她在游玩时突然想到:由于涂鸦者跳跃能力有限,是否可能存在某个平台,使其永远无法抵达?请考虑如下问题:

共有 nn 个平台。第 xx 个平台(1≤x≤n1 \le x \le n)的高度为 a⋅x mod pa \cdot x \bmod p,其中 aa 和 pp 是互质的正整数。涂鸦者单次跳跃所能达到的最大高度差为 hh,即:若当前位于高度 h1h_1,则可跳至更高处的平台高度 h2h_2(h1<h2h_1 < h_2),当且仅当 h2−h1≤hh_2 - h_1 \le h。初始时,涂鸦者位于地面,高度为 00。问题是:它能否抵达所有平台中最高的那个平台?

例如,当 a=7a = 7、n=4n = 4、p=12p = 12、h=2h = 2 时,各平台高度依次为 7,2,9,47, 2, 9, 4,如下图所示。涂鸦者第一次跳跃可到达高度为 22 的平台,第二次跳跃可到达高度为 44 的平台;但此后无法再跳至任何更高的平台。因此,它无法抵达最高平台。

用户小道思考该问题许久却未能解决,于是向你求助。此外,她手头还有大量此类问题实例。你的任务是解决所有这些实例。

输入格式

The first line contains an integer t (1 ≤ t ≤ 104) — the number of problem instances. Each of the next t lines contains four integers a, n, p and h (1 ≤ a ≤ 109, 1 ≤ n < p ≤ 109, 0 ≤ h ≤ 109). It's guaranteed that a and p are co-prime.

第一行包含一个整数 tt(1 ≤ t ≤ 1041 \leq t \leq 10^4)—— 问题实例的个数。接下来的 tt 行中,每行包含四个整数 aa、nn、pp 和 hh(1 ≤ a ≤ 1091 \leq a \leq 10^9,1 ≤ n < p ≤ 1091 \leq n < p \leq 10^9,0 ≤ h ≤ 1090 \leq h \leq 10^9)。保证 aa 与 pp 互质。

输出格式

For each problem instance, if the Doodler can reach the highest platform, output "YES", otherwise output "NO".

对于每个问题实例,如果涂鸦者能够到达最高的平台,则输出 “YES”,否则输出 “NO”。

输入输出样例

  • 输入#1

    3
    7 4 12 2
    7 1 9 4
    7 4 12 3

    输出#1

    NO
    NO
    YES

输入解题思路,AI测评打分。不知道怎么写?

首页