Division Versus Addition
시간 제한2초메모리 제한2048 MB
각 질의 구간에서 포비가 원소를 반으로 줄이고 레클스가 원소를 1 늘리는 게임의 값을 구한다. 포비는 줄이는 횟수를 최소화하고 레클스는 최대화한다.
문제
For an array of length (), 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 and replace it with . In other words, he picks () such that , then does .
- On Rekkles' turn, he must choose an element from the array and replace it with . In other words, he picks () such that , then does .
The game ends once all elements in the array are equal to .
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 is the score of the game when both players play optimally.
You are given an integer array of length ().
Answer independent queries. In each query, you are given a range and must find the value of the array .
입력
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains two integers and () --- the length of the array and the number of queries.
The next line contains integers () --- the elements of the array .
Then lines follow. The -th of them contains two integers and () --- the range of the subarray for the -th query.
It is guaranteed that the sum of over all test cases does not exceed .
It is guaranteed that the sum of over all test cases does not exceed .
출력
For each test case, output lines. The -th line should contain a single integer representing the answer to the -th query.
힌트
Explanation of the first test case, first query (1 1):
The subarray is .
- Poby: . The array is .
- Rekkles: . The array is .
- Poby: . The array is , so the game ends.
It can be shown that this strategy is optimal for both players. Therefore, the value of the array is .
Explanation of the first test case, second query (1 2):
The subarray is .
- Poby: . The array is .
- Rekkles: . The array is .
- Poby: . The array is .
- Rekkles: . The array is .
- Poby: . The array is , so the game ends.
It can be shown that this strategy is optimal for both players. Therefore, the value of the array is .