PivotOJ

Exponents

시간 제한: 2000ms메모리 제한: 2048MB출처: BOI 2025BOJ 33858

문제

The famous polymath Nicolaus Copernicus was born and grew up in Toruń in the 15th century. Archaeologists have recently discovered his notebook, and learned that he was fond of using powers of two to store large numbers. In particular, even when he added two powers of two:

2a+2b,2^a + 2^b,

Copernicus evaluated the result and then rounded up the result to the nearest power of two. That is, he would evaluate 2a+2b2^a + 2^b to 2max(a,b)+12^{\max(a,b)+1}. To evaluate a longer expression of the form:

2b1+2b2++2bk,2^{b_1} + 2^{b_2} + \dots + 2^{b_k},

he first inserted the brackets to make it well-parenthesised^∗. For example, an expression 25+24+24+24+252^5 + 2^4 + 2^4 + 2^4 + 2^5 can be made well-parenthesised to obtain ((25+24)+(24+(24+25)))((2^5 + 2^4 ) + (2^4 + (2^4 + 2^5 ))). Finally, he evaluated the result of the obtained well-parenthesised expression, operating on powers of two as described above. Notice that the obtained result might vary depending on how he inserts the brackets. For example, here are two possible ways to evaluate 25+24+24+24+252^5 + 2^4 + 2^4 + 2^4 + 2^5:

(((25+24)+24)+(24+25))=((26+24)+26)=(27+26)=28(((2^5 + 2^4 ) + 2^4 ) + (2^4 + 2^5 )) = ((2^6 + 2^4 ) + 2^6 ) = (2^7 + 2^6 ) = 2^8

((25+(24+24))+(24+25))=((25+25)+26)=(26+26)=27((2^5 + (2^4 + 2^4 )) + (2^4 + 2^5 )) = ((2^5 + 2^5 ) + 2^6 ) = (2^6 + 2^6 ) = 2^7

The first page of the Copernicus’ notebook contains only a single expression 2a1+2a2++2an2^{a_1} + 2^{a_2} + \dots + 2^{a_n} called the main expression. Later pages of the notebook then reference fragments of the main expression, which are of the form 2a+2a+1++2ar2^{a_ℓ} + 2^{a_{ℓ+1}} + \dots + 2^{a_r}, for some 1 ≤ ℓ ≤ r ≤ n.

You are not sure about their meaning, but suspect that you should calculate, for each such fragment, the smallest possible result that can be obtained when evaluating the result as described above for the fragment. Note that each fragment is evaluated independently of the other fragments.


^∗The formal definition of a well-parenthesised expression is as follows: 2a2^a is a well-parenthesised expression for any non-negative integer aa; if E1E_1 and E2E_2 are well-parenthesised expressions then so is (E1+E2)(E_1 + E_2). No other expressions are well-parenthesised.

입력

The first line contains two integers nn and qq (1 ≤ n, q ≤ 300\, 000) denoting the length of the main expression from the first page of the notebook and the number of queries, respectively.

The second line contains nn integers a1,a2,,ana_1, a_2, \dots , a_n (0 ≤ a_i ≤ 10^6), where the ii-th integer ai denotes the exponent of the ii-th power of two in the main expression.

The next qq lines describe the queries. Each query consists of two integers and rr (1 ≤ ℓ ≤ r ≤ n) representing a fragment of the main expression starting at the -th power of two and ending at the rr-th power of two.

출력

You should output qq lines. The ii-th line should contain the smallest possible result that can be obtained when evaluating the fragment described in the ii-th query. You should output only the exponent of the corresponding power of two.

예제

예제 1

입력
8 4
2 4 2 5 4 4 4 5
4 8
1 4
2 5
1 7
출력
7
7
7
8
코드를 제출하려면 로그인하세요.