Limits 2s, 256 MB

Dengue, the talk of the town of Dhaka this year. So many people suffered from dengue fever and a number of people died. In this problem, you are going to process some queries with some given information about the affects of dengue.

There are nn most dengue affected areas in Bangladesh. These are numbered from 1 to nn. The affect value of the ii-th area is affecti\text{affect}_i. Now, you need to process mm queries.

A query is defined as L R P Q: You need to print,

  • Count of areas numbered from LL to RR where dengue affect is at least PP and at most QQ.

  • Minimum affect value which is present in area LL to RR and between PP to QQ. If there is no such value, print -1.

  • Maximum affect value which is present in area LL to RR and between PP to QQ. If there is no such value, print -1.

Input

The first line of input will contain two integers nn and mm (1n,m1051 ≤ n, m ≤ 10^5).

The next line will contain nn integers denoting affect1\text{affect}_1, affect2\text{affect}_2, ..., affectn\text{affect}_n (1affecti1091 ≤ \text{affect}_i ≤ 10^9).

The next mm lines will be followed by four integer LL, RR, PP and QQ (1LRn1 ≤ L ≤ R ≤ n, 1PQ1091 ≤ P ≤ Q ≤ 10^9).

Output

For each query, output three integers as defined in the problem statement.

Sample

InputOutput
3 2
1 2 3
1 3 1 3
1 3 4 5
3 1 3
0 -1 -1

In the first query, there are three affect values [1,2,3][1, 2, 3] between P=1P = 1 and Q=3Q = 3 in area L=1L = 1 to R=3R = 3. So the first integer of the output is 3. Among these, the minimum is 1 and the maximum is 3, so the next two integers of the output is 1 and 2 respectively.

In the second query, there is no affect value between P=4P = 4 and Q=5Q = 5 in area L=1L = 1 to R=3R = 3.


Submit

Login to submit.

Statistics

69% Solution Ratio
prodip_bsmrstuEarliest, Sep '19
mdshadeshFastest, 0.0s
mdshadeshLightest, 24 kB
SoudipShortest, 1398B
Toph uses cookies. By continuing you agree to our Cookie Policy.