AT_arc171_d.[ARC171D] Rolling Hash

省选/NOI-

通过率:0%

AC君温馨提醒

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

题目描述

给定整数 P,BP,B 满足 PP 是质数,1≤B≤P−11\le B\le P-1。

对于序列 X=(x1,x2,⋯ ,xn)X=(x_1,x_2,\cdots,x_n),定义 hash⁡(X)\operatorname{hash}(X) 的值为

hash⁡(X)=(∑i=1nxiBn−i) mod P\operatorname{hash}(X)=\left(\sum_{i=1}^nx_iB^{n-i}\right)\bmod P

给定 MM 对整数 (Li,Ri)(1≤i≤M)(L_i,R_i)(1\le i\le M),请问是否存在长度为 NN 的序列 A=(A1,A2,⋯ ,AN)A=(A_1,A_2,\cdots,A_N) 满足:

  • 对每一个 i(1≤i≤M)i(1\le i\le M),都有

    hash⁡((ALi,ALi+1,⋯ ,ARi))≠0\operatorname{hash}((A_{L_i},A_{L_i+1},\cdots,A_{R_i}))\not=0

输入格式

第一行四个整数 P,B,N,MP,B,N,M,接下来 MM 行每行两个整数 Li,RiL_i,R_i。

输出格式

若存在 AA 满足要求输出 Yes,否则输出 No。

样例 1 解释

序列 A=(2,0,4)A=(2,0,4) 满足要求。其中

  • hash⁡((A1))=2\operatorname{hash}((A_1))=2
  • hash⁡((A1,A2))=1\operatorname{hash}((A_1,A_2))=1
  • hash⁡((A2,A3))=1\operatorname{hash}((A_2,A_3))=1

输入输出样例

  • 输入#1

    3 2 3 3
    1 1
    1 2
    2 3

    输出#1

    Yes
  • 输入#2

    2 1 3 3
    1 1
    2 3
    1 3

    输出#2

    No
  • 输入#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

    输出#3

    Yes

说明/提示

  • 2≤P≤1092 \leq P \leq 10^9
  • PP 是质数。
  • 1≤B≤P−11 \leq B \leq P - 1
  • 1≤N≤161 \leq N \leq 16
  • 1≤M≤N(N+1)21 \leq M \leq \frac{N(N+1)}{2}
  • 1≤Li≤Ri≤N1 \leq L_i \leq R_i \leq N
  • (Li,Ri)≠(Lj,Rj)(L_i, R_i) \neq (L_j, R_j) if i≠ji \neq j.
  • 所有的输入都是整数。

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

首页