Best Subsequence

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

문제

We call WW a kk-best number of sequence B_1...mB\_{1...m} if there exists a sequence C_1...kC\_{1...k} satisfying the following two conditions:

  1. C_1...kC\_{1...k} is a subsequence of B_1...mB\_{1...m}.
  2. i\[1,k],C_i+C_(imodk)+1W\forall i \in \[1, k], C\_{i} + C\_{(i \bmod k) + 1} \le W.

Given a sequence A_1...nA\_{1...n}, you need to answer QQ questions. Each question consists of three integers L,R,KL, R, K, and you need to calculate the minimum KK-best number of A_L...RA\_{L...R}.

Recall that CC is a subsequence of BB if and only if we can obtain CC by removing some elements of BB (possibly none or all).

입력

The first line contains two integers nn and QQ (1n,Q1051 \le n, Q \le 10^5).

The second line contains nn integers A_1...nA\_{1...n} (0A_i1090 \le A\_i \le 10^9).

Then QQ lines follow. Each of them contains three integers L,R,KL, R, K, representing a question (1LRn1 \le L \le R \le n; 1KRL+11 \le K \le R - L + 1).

출력

For each question, output a single line with a single integer: the answer.