Under construction

Still being built. Things may change

Ascending Order

Time limit1sMemory limit1024 MB

Summary
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.
Level

Medium7 of 10

Topics
Greedy, Array, Math
Solved
No attempts yet

Problem

A sequence of positive integers X1,…,XMX_1, \dots, X_M of length MM is given. Consider making this sequence ascending. The sequence X1,…,XMX_1, \dots, X_M is ascending if Xi≤Xi+1X_i \le X_{i+1} holds for every ii (1≤i≤M−11 \le i \le M-1).

To make XX ascending, you may apply the following operation as many times as you want.

  • Choose an index ii (1≤i≤M1 \le i \le M) and multiply XiX_i by 22.

Let f(X)f(X) be the minimum number of operations needed to make XX ascending.

You are given a sequence of positive integers A1,…,ANA_1, \dots, A_N and QQ queries. Each query gives integers ll and rr with 1≤l≤r≤N1 \le l \le r \le N. The answer to the query is f(Al,…,Ar)f(A_l, \dots, A_r), where Al,…,ArA_l, \dots, A_r is the contiguous subsequence from the ll-th to the rr-th element of AA.

Find the answer to each query.

Input

The first line contains NN and QQ, separated by a space.

The second line contains A1,…,ANA_1, \dots, A_N, separated by spaces.

Each of the following QQ lines contains a query, given as ll and rr, separated by a space.

Output

Print QQ lines. The kk-th line contains the answer to the kk-th query.

Constraints

  • All given numbers are integers.
  • 1≤N≤2500001 \le N \le 250000
  • 1≤Q≤2500001 \le Q \le 250000
  • 1≤Ai≤1091 \le A_i \le 10^9 (1≤i≤N1 \le i \le N)
  • For every query, 1≤l≤r≤N1 \le l \le r \le N.

Examples2

  1. Example 1

    Input
    10 5
    5 2 7 3 2 9 6 3 3 5
    3 9
    1 10
    1 8
    2 4
    8 9
    
    Expected output
    14
    27
    19
    2
    0
    
  2. Example 2

    Input
    10 5
    2 8 4 9 10 8 5 3 7 7
    2 8
    1 10
    3 3
    1 3
    8 10
    
    Expected output
    7
    11
    0
    1
    0