#P1824D. LuoTianyi and the Function
LuoTianyi and the Function
No submission language available for this problem.
Description
LuoTianyi gives you an array of integers and the index begins from .
Define as follows:
- is the largest integer that satisfies while ;
- and while .
There are queries. For each query you are given four integers , you need to calculate .
The first line contains two integers and () — the length of the array and the number of queries.
The second line contains integers () — the elements of the array .
Next lines describe a query. The -th line contains four integers () — the integers in the -th query.
Print lines where -th line contains one integer — the answer for the -th query.
Input
The first line contains two integers and () — the length of the array and the number of queries.
The second line contains integers () — the elements of the array .
Next lines describe a query. The -th line contains four integers () — the integers in the -th query.
Output
Print lines where -th line contains one integer — the answer for the -th query.
Note
In the first example:
In the first query, the answer is .
can satisfies , is the largest integer so .
In the second query, the answer is .
In the third query, the answer is , because all and .
In the fourth query, the answer is .
In the second example:
In the second query, the answer is .
In the fourth query, the answer is .