#arc171d. D - Rolling Hash
D - Rolling Hash
Score: points
问题陈述
给定非负整数 和 。这里, 是素数,。 对于非负整数序列 ,哈希值 定义如下。
$\displaystyle \mathrm{hash}(X) = \left(\sum_{i=1}^n x_i B^{n-i}\right) \bmod P$
给定 对整数 。 是否存在长度为 的非负整数序列 ,满足以下条件?
- 对于所有 ,以下条件成立:
- 令 是通过取 的第 个到第 个元素得到的序列 。那么,。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
You are given non-negative integers and . Here, is prime, and .
For a sequence of non-negative integers , the hash value is defined as follows.
$\displaystyle \mathrm{hash}(X) = \left(\sum_{i=1}^n x_i B^{n-i}\right) \bmod P$
You are given pairs of integers .
Is there a sequence of non-negative integers of length that satisfies the condition below?
- For all , the following condition holds:
- Let be the sequence obtained by taking the -th to the -th elements of . Then, .
Constraints
- is prime.
- if .
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
If there is a sequence that satisfies the condition in the problem statement, print Yes
; otherwise, print No
.
Sample Input 1
3 2 3 3
1 1
1 2
2 3
Sample Output 1
Yes
The sequence satisfies the condition because $\mathrm{hash}((A_1)) = 2, \mathrm{hash}((A_1, A_2)) = 1, \mathrm{hash}((A_2, A_3)) = 1$.
Sample Input 2
2 1 3 3
1 1
2 3
1 3
Sample Output 2
No
No sequence satisfies the condition.
Sample Input 3
998244353 986061415 6 11
1 5
2 2
2 5
2 6
3 4
3 5
3 6
4 4
4 5
4 6
5 6
Sample Output 3
Yes