Division Versus Addition

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

요약
각 질의 구간에서 포비가 원소를 반으로 줄이고 레클스가 원소를 1 늘리는 게임의 값을 구한다. 포비는 줄이는 횟수를 최소화하고 레클스는 최대화한다.
난이도

어려움10점 중 8점

유형
게임 이론, 그리디, 수학, 누적 합
정답자
아직 제출이 없습니다

문제

For an array b=\[b_1,b_2,…,b_m]b=\[b\_1,b\_2,\ldots,b\_m] of length mm (b_i≥2b\_i \geq 2), consider the following two-player game played by Poby and Rekkles.

  • The players take turns, with Poby moving first.
  • On Poby's turn, he must choose an element x≥2x \ge 2 and replace it with ⌊x2⌋\left\lfloor \frac{x}{2} \right\rfloor. In other words, he picks ii (1≤i≤m1 \leq i \leq m) such that b_i≥2b\_i \ge 2, then does b_i:=⌊b_i2⌋b\_i := \left\lfloor \frac{b\_i}{2} \right\rfloor.
  • On Rekkles' turn, he must choose an element x≥2x \ge 2 from the array bb and replace it with x+1x+1. In other words, he picks ii (1≤i≤m1 \leq i \leq m) such that b_i≥2b\_i \ge 2, then does b_i:=b_i+1b\_i := b\_i+1.

The game ends once all elements in the array bb are equal to 11.

Define the score of the game as the number of moves that Poby makes. Poby's goal is to minimize the score, while Rekkles's goal is to maximize the score.

Then, the value of the array bb is the score of the game when both players play optimally.

You are given an integer array aa of length nn (a_i≥2a\_i \ge 2).

Answer qq independent queries. In each query, you are given a range 1≤l≤r≤n1 \leq l \leq r \leq n and must find the value of the array \[a_l,a_l+1,…,a_r]\[a\_l, a\_{l+1}, \ldots, a\_r].

입력

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains two integers nn and qq (1≤n,q≤250,0001 \le n, q \le 250\\,000) --- the length of the array and the number of queries.

The next line contains nn integers a_1,a_2,…,a_na\_1, a\_2, \ldots, a\_n (2≤a_i≤1092 \le a\_i \le 10^9) --- the elements of the array aa.

Then qq lines follow. The jj-th of them contains two integers l_jl\_j and r_jr\_j (1≤l_j≤r_j≤n1 \le l\_j \le r\_j \le n) --- the range of the subarray for the ii-th query.

It is guaranteed that the sum of nn over all test cases does not exceed 250,000250\\,000.

It is guaranteed that the sum of qq over all test cases does not exceed 250,000250\\,000.

출력

For each test case, output qq lines. The ii-th line should contain a single integer representing the answer to the ii-th query.

힌트

Explanation of the first test case, first query (1 1):

The subarray is \[4]\[4].

  1. Poby: 4→⌊42⌋=24\to \left\lfloor \tfrac{4}{2}\right\rfloor=2. The array is \[2]\[2].
  2. Rekkles: 2→32\to 3. The array is \[3]\[3].
  3. Poby: 3→⌊32⌋=13\to \left\lfloor \tfrac{3}{2}\right\rfloor=1. The array is \[1]\[1], so the game ends.

It can be shown that this strategy is optimal for both players. Therefore, the value of the array \[4]\[4] is 22.

Explanation of the first test case, second query (1 2):

The subarray is \[4,3]\[4,3].

  1. Poby: 3→⌊32⌋=13\to \left\lfloor \tfrac{3}{2}\right\rfloor=1. The array is \[4,1]\[4,1].
  2. Rekkles: 4→54\to 5. The array is \[5,1]\[5,1].
  3. Poby: 5→⌊52⌋=25\to \left\lfloor \tfrac{5}{2}\right\rfloor=2. The array is \[2,1]\[2,1].
  4. Rekkles: 2→32\to 3. The array is \[3,1]\[3,1].
  5. Poby: 3→⌊32⌋=13\to \left\lfloor \tfrac{3}{2}\right\rfloor=1. The array is \[1,1]\[1,1], so the game ends.

It can be shown that this strategy is optimal for both players. Therefore, the value of the array \[4,3]\[4,3] is 33.

예제1

  1. 예제 1

    입력
    2
    5 5
    4 3 2 5 6
    1 1
    1 2
    2 4
    3 5
    1 5
    10 1
    314 159 265 358 979 323 846 264 338 327
    1 10
    
    예상 출력
    2
    3
    5
    6
    10
    91