| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 2048 MB | 81 | 76 | 71 | 93.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 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.
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
Explanation of the first test case, first query (1 1):
The subarray is $[4]$.
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]$.
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번