#P12430. [BalticOI 2025] Exponents
[BalticOI 2025] Exponents
题目描述
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:
Copernicus evaluated the result and then rounded up the result to the nearest power of two. That is, he would evaluate to . To evaluate a longer expression of the form:
he first inserted the brackets to make it well - parenthesised*. For example, an expression can be made well - parenthesised to obtain . Finally, he evaluated the result of the obtained well - parenthesised expression, operating on powers of two as described above. Notice that the 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^5))=((2^6+2^4)+2^5)=(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 called the main expression. Later pages of the notebook then reference fragments of the main expression, which are of the form , for some .
You are not sure what 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 first line contains two integers and () denoting the length of the main expression from the first page of the notebook and the number of queries, respectively.
The second line contains integers (), where the - th integer denotes the exponent of the - th power of two in the main expression.
The next lines describe the queries. Each query consists of two integers and () representing a fragment of the main expression starting at the - th power of two and ending at the - th power of two.
输出格式
You should output lines. The - th line should contain the smallest possible result that can be obtained when evaluating the fragment described in the - th query. You should output only the exponent of the corresponding power of two.
8 4
2 4 2 5 4 4 4 5
4 8
1 4
2 5
1 7
7
7
7
8
提示
Subtasks | Constrains | Score |
---|---|---|
1 | 6 | |
2 | 8 | |
3 | 23 | |
4 | 22 | |
5 | No addition constrains | 41 |