Even Intervals

아직 제출이 없습니다시간 제한20초메모리 제한1024 MB

문제

You are given an array with nn pairwise different values: A=\[a_0,a_1,,a_n1]A = \[a\_0, a\_1, \dots, a\_{n-1}]. We define the sorted subarray of AA starting at ll and ending at rr as the array that we obtain after sorting \[a_l,a_l+1,,a_r]\[a\_l, a\_{l+1}, \dots, a\_r]. For example, if we are given the array \[0,2,14,6,8,10]\[0,2,14,6,8,10], the sorted subarray starting at 11 and ending at 44 would be the array that we would get after sorting \[2,14,6,8]\[2,14,6,8], that is, the array \[2,6,8,14]\[2,6,8,14].

You are given qq queries, each one consists of two integers, ll and rr. For each query, print the sum of the values in the even positions of the sorted subarray of AA starting at ll and ending at rr. Here, we assume that all arrays are indexed starting from 00.

For example, consider the array \[0,2,14,6,8,10]\[0,2,14,6,8,10] and the query (1,4)(1,4). The subarray starting at 11 and ending at 44 is just the array \[2,14,6,8]\[2,14,6,8]. Thus, the sorted subarray starting at 11 and ending at 44 is the array \[2,6,8,14]\[2,6,8,14]. Now we have to sum the values in even positions, that is, 2+8=102+8 = 10.

Print the answers modulo 109+710^9 + 7.

입력

The first line contains two integers nn and qq (1n51041 \leq n \leq 5 \cdot 10^4; 1q21051 \leq q \leq 2 \cdot 10^5): the number of elements in the array and the number of queries.

The second line contains nn integers a_0,a_1,,a_n1a\_0, a\_1, \dots, a\_{n-1} (0a_i1090 \leq a\_i \leq 10^9; a_ia\_i are pairwise different), the elements of the array.

Finally, each of the next qq lines contains two integers ll and rr (0lr<n0 \leq l \leq r < n): the starting and ending points of the sorted subarray we are considering.

출력

For each query, print a line with the sum of the elements in even positions of the sorted subarray starting at ll and ending at rr modulo 109+710^9 + 7.