Exponents

시간 제한2초메모리 제한2048 MB

요약
부분 배열마다 2^a+2^b를 2^(max(a,b)+1)로 계산하는 규칙을 적용할 때 얻을 수 있는 가장 작은 지수를 구한다.
난이도

어려움10점 중 9점

유형
동적 계획법, 그리디, 세그먼트 트리, 스택
정답자
아직 제출이 없습니다

문제

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:

2b_1+2b_2+⋯+2b_k,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 2a_1+2a_2+⋯+2a_n2^{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+⋯+2a_r2^{a\_ℓ} + 2^{a\_{ℓ+1}} + \dots + 2^{a\_r}, for some 1≤ℓ≤r≤n1 ≤ ℓ ≤ 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 E_1E\_1 and E_2E\_2 are well-parenthesised expressions then so is (E_1+E_2)(E\_1 + E\_2). No other expressions are well-parenthesised.

입력

The first line contains two integers nn and qq (1≤n,q≤300,0001 ≤ 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 a_1,a_2,…,a_na\_1, a\_2, \dots , a\_n (0≤a_i≤1060 ≤ 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≤n1 ≤ ℓ ≤ 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

  1. 예제 1

    입력
    8 4
    2 4 2 5 4 4 4 5
    4 8
    1 4
    2 5
    1 7
    
    예상 출력
    7
    7
    7
    8