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

34629번 - Division Versus Addition 다국어

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

문제

For an array $b=[b_1,b_2,\ldots,b_m]$ of length $m$ ($b_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 \ge 2$ and replace it with $\left\lfloor \frac{x}{2} \right\rfloor$. In other words, he picks $i$ (1ドル \leq i \leq m$) such that $b_i \ge 2,ドル then does $b_i := \left\lfloor \frac{b_i}{2} \right\rfloor$.
  • On Rekkles' turn, he must choose an element $x \ge 2$ from the array $b$ and replace it with $x+1$. In other words, he picks $i$ (1ドル \leq i \leq m$) such that $b_i \ge 2,ドル then does $b_i := b_i+1$.

The game ends once all elements in the array $b$ are equal to 1ドル$.

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 $b$ is the score of the game when both players play optimally.

You are given an integer array $a$ of length $n$ ($a_i \ge 2$).

Answer $q$ independent queries. In each query, you are given a range 1ドル \leq l \leq r \leq n$ and must find the value of the array $[a_l, a_{l+1}, \ldots, a_r]$.

입력

Each test contains multiple test cases. The first line contains the number of test cases $t$ (1ドル \le t \le 10^4$). The description of the test cases follows.

The first line of each test case contains two integers $n$ and $q$ (1ドル \le n, q \le 250,000円$) --- the length of the array and the number of queries.

The next line contains $n$ integers $a_1, a_2, \ldots, a_n$ (2ドル \le a_i \le 10^9$) --- the elements of the array $a$.

Then $q$ lines follow. The $j$-th of them contains two integers $l_j$ and $r_j$ (1ドル \le l_j \le r_j \le n$) --- the range of the subarray for the $i$-th query.

It is guaranteed that the sum of $n$ over all test cases does not exceed 250ドル,000円$.

It is guaranteed that the sum of $q$ over all test cases does not exceed 250ドル,000円$.

출력

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

제한

예제 입력 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

예제 출력 1

2
3
5
6
10
91

노트

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

The subarray is $[4]$.

  1. Poby: 4ドル\to \left\lfloor \tfrac{4}{2}\right\rfloor=2$. The array is $[2]$.
  2. Rekkles: 2ドル\to 3$. The array is $[3]$.
  3. Poby: 3ドル\to \left\lfloor \tfrac{3}{2}\right\rfloor=1$. The array is $[1],ドル so the game ends.

It can be shown that this strategy is optimal for both players. Therefore, the value of the array $[4]$ is 2ドル$.

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

The subarray is $[4,3]$.

  1. Poby: 3ドル\to \left\lfloor \tfrac{3}{2}\right\rfloor=1$. The array is $[4,1]$.
  2. Rekkles: 4ドル\to 5$. The array is $[5,1]$.
  3. Poby: 5ドル\to \left\lfloor \tfrac{5}{2}\right\rfloor=2$. The array is $[2,1]$.
  4. Rekkles: 2ドル\to 3$. The array is $[3,1]$.
  5. Poby: 3ドル\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,3]$ is 3ドル$.

출처

Contest > Codeforces > Squarepoint Challenge (Codeforces Round 1055, Div. 1 + Div. 2) D번

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

출처

대학교 대회

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

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