CF575A.Fibonotci

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Fibonotci sequence is an integer recursive sequence defined by the recurrence relation

Fn=sn1Fn1+sn2Fn2F_{n}=s_{n-1}·F_{n-1}+s_{n-2}·F_{n-2} with F0=0,F1=1F_{0}=0,F_{1}=1 Sequence ss is an infinite and almost cyclic sequence with a cycle of length NN . A sequence ss is called almost cyclic with a cycle of length NN if , for i>=Ni>=N , except for a finite number of values sis_{i} , for which ( i>=Ni>=N ).

Following is an example of an almost cyclic sequence with a cycle of length 4:

s = (5,3,8,11,5,3,7,11,5,3,8,11,…) Notice that the only value of ss for which the equality does not hold is s6s_{6} ( s6=7s_{6}=7 and s2=8s_{2}=8 ). You are given s0,s1,...sN1s_{0},s_{1},...s_{N-1} and all the values of sequence ss for which ( i>=Ni>=N ).

Find .

输入格式

The first line contains two numbers KK and PP . The second line contains a single number NN . The third line contains NN numbers separated by spaces, that represent the first NN numbers of the sequence ss . The fourth line contains a single number MM , the number of values of sequence ss for which . Each of the following MM lines contains two numbers jj and vv , indicating that and sj=vs_{j}=v . All j-s are distinct.

  • 1<=N,M<=500001<=N,M<=50000
  • 0<=K<=10180<=K<=10^{18}
  • 1<=P<=1091<=P<=10^{9}
  • 1<=si<=1091<=s_{i}<=10^{9} , for all i=0,1,...N1i=0,1,...N-1
  • N<=j<=1018N<=j<=10^{18}
  • 1<=v<=1091<=v<=10^{9}
  • All values are integers

输出格式

Output should contain a single integer equal to .

输入输出样例

  • 输入#1

    10 8
    3
    1 2 1
    2
    7 3
    5 4
    

    输出#1

    4
    
首页