问题 F: Product of Sorting Powers

内存限制:512 MB 时间限制:15 S
题面:传统 评测方式:文本比较 上传者:
提交:2 通过:1

题目描述

Given a sequence A of length n.

There are m queries, each given l, r, let B1,B2,,Brl+1 as the result of sorting A_rAl,Al+1,,Ar, calculate:





输入格式

The first line of the input contains two integers n, m (1n10^6, 1m5000) - the length of A and the number of queries.

The second line contains n integers A1,A2,,An (1Ai10^9).

Each of the following m lines contains two integers l, r (1lrn).

 

输出格式

For each query, print a single integer - the answer of the query, modulo 10^9+7.

输入样例 复制

6 5
8 2 5 9 7 7
1 4
2 6
1 3
3 6
2 5

输出样例 复制

588255953
426219106
12500000
575819351
16793812

分类标签