#P5498. [LnOI2019] 脸滚键盘
[LnOI2019] 脸滚键盘
Background
Problem provider: Okami.
Asada Shino: A good long-necked deer can count the number of digits in numbers.
Problem Description
The giraffe Abbi likes to roll its face on the keyboard. Each time it does so, it multiplies the values in some sub-interval.
A sub-interval is a contiguous interval within an interval.
The weight of a sub-interval is defined as the product of the weights of all its elements.
The expected weight of an interval is defined as the expected value of the weight of a sub-interval chosen uniformly at random from all sub-intervals of that interval.
Given numbers, where the -th number is the weight .
There are queries. For each query , ask for the expected weight of the specified interval.
Input Format
The first line contains two integers and .
The second line contains integers, the -th integer is the initial value of the sequence.
The next lines each contain two integers , representing the query interval.
Output Format
For each query, output the expected weight of the specified interval.
Since the expected weight can be very large, output the expected weight modulo .
Do not ask what to do if it is not divisible; see above.
If it still does not work, please refer to https://www.luogu.org/problem/P2613.
5 3
6 12 6 3 27
1 1
4 5
1 3
6
37
100
Hint
Time and memory limits: 1 s / 512 MB.
For of the testdata, .
For of the testdata, , .
Sample explanation: For the interval , there is only one sub-interval with weight . The probability of choosing each sub-interval is , so the expected weight is 6.
For the interval , there are three sub-intervals , , and , with weights , , and respectively. The probability of choosing each sub-interval is , so the total expected weight is .
For the interval , there are six sub-intervals , , , , , and , with weights , , , , , and respectively. The probability of choosing each sub-interval is , so the total expected weight is .
It is recommended to use fast input.
Translated by ChatGPT 5