CF633H.Fibonacci-ish II
NOI/NOI+/CTSC
通过率:0%
时间限制:5.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Yash is finally tired of computing the length of the longest Fibonacci-ish sequence. He now plays around with more complex things such as Fibonacci-ish potentials.
Fibonacci-ish potential of an array a__i is computed as follows:
- Remove all elements j if there exists i < j such that a__i = a__j.
- Sort the remaining elements in ascending order, i.e. _a_1 < _a_2 < ... < a__n.
- Compute the potential as P(a) = _a_1·_F_1 + _a_2·_F_2 + ... + a__n·F__n, where F__i is the i-th Fibonacci number (see notes for clarification).
You are given an array a__i of length n and q ranges from l__j to r__j. For each range j you have to compute the Fibonacci-ish potential of the array b__i, composed using all elements of a__i from l__j to r__j inclusive. Find these potentials modulo m.
亚什终于厌倦了计算最长斐波那契式序列的长度,转而研究更复杂的问题,例如斐波那契式势能(Fibonacci-ish potential)。
数组 ai 的斐波那契式势能定义如下:
- 删除所有满足如下条件的元素 aj:存在某个 i<j,使得 ai=aj;
- 将剩余元素按升序排列,即 a1<a2<⋯<an;
- 计算势能 P(a)=a1⋅F1+a2⋅F2+⋯+an⋅Fn,其中 Fi 表示第 i 个斐波那契数(参见“注释”部分以明确其定义)。
给定一个长度为 n 的数组 ai,以及 q 个查询区间 [lj,rj]。对每个查询 j,需构造子数组 bi,它由 ai 中下标从 lj 到 rj(含端点)的所有元素组成,并计算该子数组 bi 的斐波那契式势能。请输出所有结果对 m 取模后的值。
输入格式
The first line of the input contains integers of n and m (1 ≤ n, m ≤ 30 000) — the length of the initial array and the modulo, respectively.
The next line contains n integers a__i (0 ≤ a__i ≤ 109) — elements of the array.
Then follow the number of ranges q (1 ≤ q ≤ 30 000).
Last q lines contain pairs of indices l__i and r__i (1 ≤ l__i ≤ r__i ≤ n) — ranges to compute Fibonacci-ish potentials.
输入的第一行包含两个整数 n 和 m(1≤n,m≤30000)——分别为初始数组的长度和模数。
第二行包含 n 个整数 ai(0≤ai≤109)——数组的元素。
接下来一行给出查询区间个数 q(1≤q≤30000)。
最后 q 行每行包含一对下标 li 和 ri(1≤li≤ri≤n)——表示需计算 Fibonacci-ish 势能的区间。
输出格式
Print q lines, i-th of them must contain the Fibonacci-ish potential of the i-th range modulo m.
输出 q 行,其中第 i 行必须包含第 i 个区间对应的 Fibonacci-ish 势(模 m 意义下)。
输入输出样例
输入#1
5 10 2 1 2 1 2 2 2 4 4 5
输出#1
3 3
说明/提示
For the purpose of this problem define Fibonacci numbers as follows:
- _F_1 = _F_2 = 1.
- F__n = F__n - 1 + F__n - 2 for each n > 2.
In the first query, the subarray [1,2,1] can be formed using the minimal set {1,2}. Thus, the potential of this subarray is 1*1+2*1=3.
本题中,斐波那契数列定义如下:
- F1=F2=1;
- 对每个 n>2,有 Fn=Fn−1+Fn−2。
在第一个查询中,子数组 [1,2,1] 可由最小集合 {1,2} 构成。因此,该子数组的势为 1×1+2×1=3。
输入解题思路,AI测评打分。不知道怎么写?