#P9869. F. Product of Sorting Powers
F. Product of Sorting Powers
F. Product of Sorting Powers
Problem Description
Given a sequence of length . There are queries, each given , let as the result of sorting , calculate:
$$\left(\prod_{i = 1} ^ {r - l} {B_i} ^ {B_{i + 1}} \right) \bmod {(10 ^ 9 + 7)} $$Input
The first line of the input contains two integers (, ) - the length of and the number of queries. The second line contains integers (). Each of the following lines contains two integers ().
Output
For each query, print a single integer - the answer of the query, modulo .
Sample Input
6 5
8 2 5 9 7 7
1 4
2 6
1 3
3 6
2 5
Sample Output
588255953
426219106
12500000
575819351
16793812
Source
2023“钉耙编程”中国大学生算法设计超级联赛(7)