A10034 | Fibonotci
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Fibonotci sequence is an integer recursive sequence defined by the recurrence relation
$F_{n}=s_{n-1}·F_{n-1}+s_{n-2}·F_{n-2}$ with $F_{0}=0,F_{1}=1$ Sequence $s$ is an infinite and almost cyclic sequence with a cycle of length $N$ . A sequence $s$ is called almost cyclic with a cycle of length $N$ if , for $i>=N$ , except for a finite number of values $s_{i}$ , for which  ( $i>=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 $s$ for which the equality  does not hold is $s_{6}$ ( $s_{6}=7$ and $s_{2}=8$ ). You are given $s_{0},s_{1},...s_{N-1}$ and all the values of sequence $s$ for which  ( $i>=N$ ).
Find .
$F_{n}=s_{n-1}·F_{n-1}+s_{n-2}·F_{n-2}$ with $F_{0}=0,F_{1}=1$ Sequence $s$ is an infinite and almost cyclic sequence with a cycle of length $N$ . A sequence $s$ is called almost cyclic with a cycle of length $N$ if , for $i>=N$ , except for a finite number of values $s_{i}$ , for which  ( $i>=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 $s$ for which the equality  does not hold is $s_{6}$ ( $s_{6}=7$ and $s_{2}=8$ ). You are given $s_{0},s_{1},...s_{N-1}$ and all the values of sequence $s$ for which  ( $i>=N$ ).
Find .
输入格式
The first line contains two numbers $K$ and $P$ . The second line contains a single number $N$ . The third line contains $N$ numbers separated by spaces, that represent the first $N$ numbers of the sequence $s$ . The fourth line contains a single number $M$ , the number of values of sequence $s$ for which . Each of the following $M$ lines contains two numbers $j$ and $v$ , indicating that  and $s_{j}=v$ . All j-s are distinct.
- $1<=N,M<=50000$
- $0<=K<=10^{18}$
- $1<=P<=10^{9}$
- $1<=s_{i}<=10^{9}$ , for all $i=0,1,...N-1$
- $N<=j<=10^{18}$
- $1<=v<=10^{9}$
- All values are integers
- $1<=N,M<=50000$
- $0<=K<=10^{18}$
- $1<=P<=10^{9}$
- $1<=s_{i}<=10^{9}$ , for all $i=0,1,...N-1$
- $N<=j<=10^{18}$
- $1<=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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted