Logo
(追記) (追記ここまで)

33858번 - Exponents 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 2048 MB898815.094%

문제

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:

$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 2ドル^a + 2^b$ to 2ドル^{\max(a,b)+1}$. To evaluate a longer expression of the form:

$2ドル^{b_1} + 2^{b_2} + \dots + 2^{b_k},$$

he first inserted the brackets to make it well-parenthesised$^∗$. For example, an expression 2ドル^5 + 2^4 + 2^4 + 2^4 + 2^5$ can be made well-parenthesised to obtain $((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 2ドル^5 + 2^4 + 2^4 + 2^4 + 2^5$:

$$(((2^5 + 2^4 ) + 2^4 ) + (2^4 + 2^5 )) = ((2^6 + 2^4 ) + 2^6 ) = (2^7 + 2^6 ) = 2^8$$

$$((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 2ドル^{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 2ドル^{a_l} + 2^{a_{l+1}} + \dots + 2^{a_r},ドル for some 1ドル ≤ l ≤ 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: 2ドル^a$ is a well-parenthesised expression for any non-negative integer $a$; if $E_1$ and $E_2$ are well-parenthesised expressions then so is $(E_1 + E_2)$. No other expressions are well-parenthesised.

입력

The first line contains two integers $n$ and $q$ (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 $n$ integers $a_1, a_2, \dots , a_n$ (0ドル ≤ a_i ≤ 10^6$), where the $i$-th integer ai denotes the exponent of the $i$-th power of two in the main expression.

The next $q$ lines describe the queries. Each query consists of two integers $l$ and $r$ (1ドル ≤ l ≤ r ≤ n$) representing a fragment of the main expression starting at the $l$-th power of two and ending at the $r$-th power of two.

출력

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

제한

서브태스크

번호배점제한
16

$n ≤ 8,ドル $q ≤ 10$

28

$n ≤ 200$

323

$n, q ≤ 2000$

422

$a_i ≤ 20$

541

No additional constraints.

예제 입력 1

8 4
2 4 2 5 4 4 4 5
4 8
1 4
2 5
1 7

예제 출력 1

7
7
7
8

힌트

출처

Olympiad > Baltic Olympiad in Informatics > BOI 2025 E번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /