CF1536D.Omkar and Medians

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Uh oh! Ray lost his array yet again! However, Omkar might be able to help because he thinks he has found the OmkArray of Ray's array. The OmkArray of an array aa with elements a1,a2,,a2k1a_1, a_2, \ldots, a_{2k-1} , is the array bb with elements b1,b2,,bkb_1, b_2, \ldots, b_{k} such that bib_i is equal to the median of a1,a2,,a2i1a_1, a_2, \ldots, a_{2i-1} for all ii . Omkar has found an array bb of size nn ( 1n21051 \leq n \leq 2 \cdot 10^5 , 109bi109-10^9 \leq b_i \leq 10^9 ). Given this array bb , Ray wants to test Omkar's claim and see if bb actually is an OmkArray of some array aa . Can you help Ray?

The median of a set of numbers a1,a2,,a2i1a_1, a_2, \ldots, a_{2i-1} is the number cic_{i} where c1,c2,,c2i1c_{1}, c_{2}, \ldots, c_{2i-1} represents a1,a2,,a2i1a_1, a_2, \ldots, a_{2i-1} sorted in nondecreasing order.

输入格式

Each test contains multiple test cases. The first line contains a single integer tt ( 1t1041 \leq t \leq 10^4 ) — the number of test cases. Description of the test cases follows.

The first line of each test case contains an integer nn ( 1n21051 \leq n \leq 2 \cdot 10^5 ) — the length of the array bb .

The second line contains nn integers b1,b2,,bnb_1, b_2, \ldots, b_n ( 109bi109-10^9 \leq b_i \leq 10^9 ) — the elements of bb .

It is guaranteed the sum of nn across all test cases does not exceed 21052 \cdot 10^5 .

输出格式

For each test case, output one line containing YES if there exists an array aa such that bib_i is the median of a1,a2,,a2i1a_1, a_2, \dots, a_{2i-1} for all ii , and NO otherwise. The case of letters in YES and NO do not matter (so yEs and No will also be accepted).

输入输出样例

  • 输入#1

    5
    4
    6 2 1 3
    1
    4
    5
    4 -8 5 6 -7
    2
    3 3
    4
    2 1 2 3

    输出#1

    NO
    YES
    NO
    YES
    YES
  • 输入#2

    5
    8
    -8 2 -6 -5 -4 3 3 2
    7
    1 1 3 1 0 -2 -1
    7
    6 12 8 6 2 6 10
    6
    5 1 2 3 6 7
    5
    1 3 4 3 0

    输出#2

    NO
    YES
    NO
    NO
    NO

说明/提示

In the second case of the first sample, the array [4][4] will generate an OmkArray of [4][4] , as the median of the first element is 44 .

In the fourth case of the first sample, the array [3,2,5][3, 2, 5] will generate an OmkArray of [3,3][3, 3] , as the median of 33 is 33 and the median of 2,3,52, 3, 5 is 33 .

In the fifth case of the first sample, the array [2,1,0,3,4,4,3][2, 1, 0, 3, 4, 4, 3] will generate an OmkArray of [2,1,2,3][2, 1, 2, 3] as

  • the median of 22 is 22
  • the median of 0,1,20, 1, 2 is 11
  • the median of 0,1,2,3,40, 1, 2, 3, 4 is 22
  • and the median of 0,1,2,3,3,4,40, 1, 2, 3, 3, 4, 4 is 33 .

In the second case of the second sample, the array [1,0,4,3,5,2,2,2,4,3,4,1,5][1, 0, 4, 3, 5, -2, -2, -2, -4, -3, -4, -1, 5] will generate an OmkArray of [1,1,3,1,0,2,1][1, 1, 3, 1, 0, -2, -1] , as

  • the median of 11 is 11
  • the median of 0,1,40, 1, 4 is 11
  • the median of 0,1,3,4,50, 1, 3, 4, 5 is 33
  • the median of 2,2,0,1,3,4,5-2, -2, 0, 1, 3, 4, 5 is 11
  • the median of 4,2,2,2,0,1,3,4,5-4, -2, -2, -2, 0, 1, 3, 4, 5 is 00
  • the median of 4,4,3,2,2,2,0,1,3,4,5-4, -4, -3, -2, -2, -2, 0, 1, 3, 4, 5 is 2-2
  • and the median of 4,4,3,2,2,2,1,0,1,3,4,5,5-4, -4, -3, -2, -2, -2, -1, 0, 1, 3, 4, 5, 5 is 1-1

For all cases where the answer is NO, it can be proven that it is impossible to find an array aa such that bb is the OmkArray of aa .

首页