CF1097H.Mateusz and an Infinite Sequence
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A Thue-Morse-Radecki-Mateusz sequence (Thorse-Radewoosh sequence in short) is an infinite sequence constructed from a finite sequence gen of length d and an integer m , obtained in the following sequence of steps:
- In the beginning, we define the one-element sequence M0=(0) .
- In the k -th step, k≥1 , we define the sequence Mk to be the concatenation of the d copies of Mk−1 . However, each of them is altered slightly — in the i -th of them ( 1≤i≤d ), each element x is changed to (x+geni)(modm) .
For instance, if we pick gen=(0,1,2) and m=4 :
- M0=(0) ,
- M1=(0,1,2) ,
- M2=(0,1,2,1,2,3,2,3,0) ,
- M3=(0,1,2,1,2,3,2,3,0,1,2,3,2,3,0,3,0,1,2,3,0,3,0,1,0,1,2) , and so on.
As you can see, as long as the first element of gen is 0 , each consecutive step produces a sequence whose prefix is the sequence generated in the previous step. Therefore, we can define the infinite Thorse-Radewoosh sequence M∞ as the sequence obtained by applying the step above indefinitely. For the parameters above, M∞=(0,1,2,1,2,3,2,3,0,1,2,3,2,3,0,3,0,1,…) .
Mateusz picked a sequence gen and an integer m , and used them to obtain a Thorse-Radewoosh sequence M∞ . He then picked two integers l , r , and wrote down a subsequence of this sequence A:=((M∞)l,(M∞)l+1,…,(M∞)r) .
Note that we use the 1 -based indexing both for M∞ and A .
Mateusz has his favorite sequence B with length n , and would like to see how large it is compared to A . Let's say that B majorizes sequence X of length n (let's denote it as B≥X ) if and only if for all i∈{1,2,…,n} , we have Bi≥Xi .
He now asks himself how many integers x in the range [1,∣A∣−n+1] there are such that B≥(Ax,Ax+1,Ax+2,…,Ax+n−1) . As both sequences were huge, answering the question using only his pen and paper turned out to be too time-consuming. Can you help him automate his research?
输入格式
The first line contains two integers d and m ( 2≤d≤20 , 2≤m≤60 ) — the length of the sequence gen and an integer used to perform the modular operations. The second line contains d integers geni ( 0≤geni<m ). It's guaranteed that the first element of the sequence gen is equal to zero.
The third line contains one integer n ( 1≤n≤30000 ) — the length of the sequence B . The fourth line contains n integers Bi ( 0≤Bi<m ). The fifth line contains two integers l and r ( 1≤l≤r≤1018 , r−l+1≥n ).
输出格式
Print a single integer — the answer to the problem.
输入输出样例
输入#1
2 2 0 1 4 0 1 1 0 2 21
输出#1
6
输入#2
3 4 0 1 2 2 0 2 6 11
输出#2
1
说明/提示
Thorse-Radewoosh sequence in the first example is the standard Thue-Morse sequence, so the sequence A is as follows: 11010011001011010010 . Here are the places where the sequence B majorizes A :