Period Sequence
Time limit6sMemory limit256 MB
Given a periodic-plus-growing sequence built from n integers, compute the sum over all subarrays inside index range [a, b] of sum of x times count of x squared, modulo 1e9+7.
- Level
Hard9 of 10
- Topics
- Math, Segment tree, Combinatorics
- Solved
- No attempts yet
Statement
Chiaki has integers . She defines an infinite sequence as follows.
Here is a zero-based index.
For a contiguous subsequence , let be the number of occurrences of in . The value of is
For two integers and (), find the value of
Input
There are multiple test cases. The first line contains an integer , the number of test cases. Each test case is as follows.
The first line contains three integers , , and (, ).
The second line contains integers ().
The sum of all does not exceed .
Output
For each test case, print one integer: the answer.