#P7576. 「PMOI-3」期望乘积
「PMOI-3」期望乘积
Problem Description
ducati loves defining some strange things.
-
Two sequences are defined to be different if and only if their lengths are different, or they have the same length but there exists at least one position where the corresponding values are different.
-
The weight of a sequence is defined as the product of all numbers in .
-
The reachability between sequences is defined as follows:
- Perform exactly operations. In each operation, choose a subarray of (note that the chosen subarray can be empty) and add to every number in the subarray. If there exists an operation plan such that after all operations, becomes exactly the same as , then we say can reach .
-
The elegance value of sequence is defined as the sum of the weights of all different sequences that are reachable from .
Now, ducati has a sequence of length . He will query the elegance value of an interval many times.
Can you help this curious person? You only need to output each answer modulo .
Input Format
The first line contains three integers , representing the length of the sequence, the number of queries, and the number of allowed modifications in each query.
The second line contains integers, representing the sequence .
The next lines each contain two positive integers , describing one query.
Output Format
For each query, output the answer modulo .
2 1 1
1 2
1 2
15
10 3 3
1 5 3 2 2 4 6 3 2 3
1 7
4 9
3 10
3850
1166
3893
Hint
[Sample Explanation 1]
is . There is a total of query.
All that can reach are as follows:
The sum of their weights is .
[Sample Explanation 2]
For the second sample, I have a wonderful explanation, but unfortunately this space is too small, so I cannot write it down.
[Constraints]
This problem uses bundled testdata.
- Subtask1 (10pts): ;
- Subtask2 (20pts): ;
- Subtask3 (30pts): , ;
- Subtask4 (40pts): no special constraints.
For of the testdata, , , , and for all queries, .
Translated by ChatGPT 5