Stefan’s New Year’s resolutions

Time limit: 1.5s Memory limit: 256MB Input: Output:

Task

Stefan has big plans for the year that just begun and among others, one of his plans is to improve his contest ratings.
While every competitive programmer dreams of this, he is perfectly aware that not everyone can achieve it.
Now he stumbled across an array that he received as a gift many years ago, together with a very old scroll containing the problem statement below.

You are given an array VV of NN positive integers, numbered from 00 to N1N-1, inclusive.
You have to answer QQ queries: given LL, RR and KK, find the product of the largest KK values of VL,VL+1,,VR1,VRV_L, V_{L+1}, \ldots, V_{R-1}, V_R.

Stefan realized that this is not a cakewalk question so now it's your turn to help him overcome this challenge and write a program that answers the queries for him.
Since the answers can be very big, you have to print them module 109+710^9 + 7 (i.e. the reminder of the division by 109+710^9 + 7).

Input data

The input file consists of:

  • a line containing integers NN, QQ.
  • a line containing the NN integers V0,,VN1V_{0}, \, \ldots, \, V_{N-1}.
  • QQ lines, the ii-th of which consisting of integers LiL_{i}, RiR_{i}, KiK_{i}.

Output data

The output file must contain a single line consisting of the QQ integers ans0,,ansQ1ans_{0}, \, \ldots, \, ans_{Q-1}.

Constraints and clarifications

  • 1N,Q2000001 \le N, Q \le 200\,000.
  • 1Vi2000001 \le V_i \le 200\,000 for each i=0N1i=0\ldots N-1.
  • 0LR<N0 \le L \le R < N for each query.
  • 1KRL+11 \le K \le R - L + 1 for each query.
# Points Constraints
1 0 Examples.
2 11 N,Q2000N, Q \le 2000
3 13 K=RL+1K = R - L + 1 for all queries
4 19 K=1K = 1 for all queries
5 25 N,Q50000N, Q \le 50\,000
6 32 No additional limitations.

Example

stdin

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

stdout

9
63
9
5103
81648
9
63
324
729
648
108
9
163296
36
2268

Explanation

For the second query of the sample case, the values between 11 and 44 are [1,9,4,7][1,9,4,7], the 22 largest values are 99 and 77 and their product is 6363.

For the fourth query of the sample case, the values between 11 and 77 are [1,9,4,7,9,4,9][1,9,4,7,9,4,9], the 44 largest values are 99, 99, 99 and 77 and their product is 51035103.

Log in or sign up to be able to send submissions!