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

27199번 - Bob's Average 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 1024 MB50191640.000%

문제

In a course in mathematical statistics, Bob came up with a new way to calculate the average for arrays containing an odd number of elements.

As long as the length of the array is greater than one, the following operation is performed: an arbitrary segment of the array of length 3 with boundaries $l$ and $r = l + 2$ is selected, the median of these three elements is calculated and then these elements are replaced by one element equal to the median.

The median of an array of three elements is the second-highest element of this array. For example, the median of the array $[1, 5, 4]$ is 4ドル,ドル and the median the array $[2, 2, 2]$ is 2ドル$.

Let's consider one of the ways to calculate the Bob's average on an array $[4, 1, 3, 2, 5]$. In the first step, we select a sub-section with boundaries $l = 2,ドル $r = 4$. Since 2ドル$ is the median of the subarray $[1, 3, 2],ドル then the array is converted as follows: $[4, 1, 3, 2, 5] \rightarrow [4, 2, 5]$. In the second step, the only possible segment of length 3ドル$ has boundaries $l = 1,ドル $r = 3$. Since 4ドル$ is the median of the subarray $[4, 2, 5],ドル then $[4, 2, 5] \rightarrow [4]$.

Bob noticed that his method of calculating the average is not quite correctly defined: depending on the choice of segments, the result of the calculation may be different. To fix this situation, Bob decided to choose segments to replace with the median in such a way that the only number remaining at the end was the maximum possible. It is this number that Bob calls Bob's average for this array.

For an array $a$ of $n$ elements, you need to answer $q$ queries, The $j$-th of those queries is characterized by the boundaries of $L_j$ and $R_j$.

The answer to the $i$-th query is the Bob's average of the segment of the original array $[a_{L_j}, a_{L_j + 1}, \ldots a_{R_j}]$. For all queries, it is guaranteed that the length of the query segment is odd.

입력

The first line contains an integer $n$ (3ドル \leq n \leq 5 \cdot 10^4$) --- array size.

The second line contains $n$ integers $a_i$ (0ドル \leq a_i \leq 10^9$) --- array elements.

The third line contains an integer $q$ (1ドル \leq q \leq 10^5$) --- number of requests.

The following $q$ lines contain integers $L_j,ドル $R_j$ (1ドル \leq L_j \leq R_j \leq n$) --- the boundaries of the sub-section of the $j$-th query, it is guaranteed that $R_j - L_j + 1$ is not divisible by 2ドル$.

출력

In the $j$-th line of the output, output a single integer --- the answer to the $j$-th request.

제한

예제 입력 1

7
4 1 3 2 5 1 7
5
2 6
1 1
1 5
3 7
1 7

예제 출력 1

2
4
4
3
4

힌트

출처

Olympiad > Russian Olympiad in Informatics > Russia Team High School Programming Contest > Russia Team High School Programming Contest 2022 F번

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

출처

대학교 대회

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

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