Ascending Order
Time limit1sMemory limit1024 MB
Given a sequence of positive integers, each query asks for the fewest doublings of elements in a subarray needed to make that subarray non-decreasing.
Problem
A sequence of positive integers of length is given. Consider making this sequence ascending. The sequence is ascending if holds for every ().
To make ascending, you may apply the following operation as many times as you want.
- Choose an index () and multiply by .
Let be the minimum number of operations needed to make ascending.
You are given a sequence of positive integers and queries. Each query gives integers and with . The answer to the query is , where is the contiguous subsequence from the -th to the -th element of .
Find the answer to each query.
Input
The first line contains and , separated by a space.
The second line contains , separated by spaces.
Each of the following lines contains a query, given as and , separated by a space.
Output
Print lines. The -th line contains the answer to the -th query.
Constraints
- All given numbers are integers.
- ()
- For every query, .