CF1536D.Omkar and Medians
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
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 a with elements a1,a2,…,a2k−1, is the array b with elements b1,b2,…,bk such that bi is equal to the median of a1,a2,…,a2i−1 for all i. Omkar has found an array b of size n (1≤n≤2⋅105, −109≤bi≤109). Given this array b, Ray wants to test Omkar's claim and see if b actually is an OmkArray of some array a. Can you help Ray?
The median of a set of numbers a1,a2,…,a2i−1 is the number ci where c1,c2,…,c2i−1 represents a1,a2,…,a2i−1 sorted in nondecreasing order.
哎呀!雷又弄丢了他的数组!不过,奥姆卡尔或许能帮忙,因为他觉得自己找到了雷的数组的“奥姆卡尔数组”(OmkArray)。对于一个含有元素 a1,a2,…,a2k−1 的数组 a,其奥姆卡尔数组(OmkArray)是数组 b,其元素为 b1,b2,…,bk,其中对每个 i,bi 等于 a1,a2,…,a2i−1 的中位数。奥姆卡尔找到了一个长度为 n 的数组 b(1≤n≤2⋅105,−109≤bi≤109)。给定该数组 b,雷想验证奥姆卡尔的说法是否成立:b 是否确实是某个数组 a 的奥姆卡尔数组?你能帮雷吗?
一组数 a1,a2,…,a2i−1 的中位数是指:将 a1,a2,…,a2i−1 按非递减顺序排序后得到序列 c1,c2,…,c2i−1,则中位数为 ci。
输入格式
Each test contains multiple test cases. The first line contains a single integer t (1≤t≤104) — the number of test cases. Description of the test cases follows.
The first line of each test case contains an integer n (1≤n≤2⋅105) — the length of the array b.
The second line contains n integers b1,b2,…,bn (−109≤bi≤109) — the elements of b.
It is guaranteed the sum of n across all test cases does not exceed 2⋅105.
每个测试包含多个测试用例。第一行包含一个整数 t(1≤t≤104),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤2⋅105),表示数组 b 的长度。
第二行包含 n 个整数 b1,b2,…,bn(−109≤bi≤109),即数组 b 的元素。
保证所有测试用例的 n 之和不超过 2⋅105。
输出格式
For each test case, output one line containing YES if there exists an array a such that bi is the median of a1,a2,…,a2i−1 for all i, and NO otherwise. The case of letters in YES and NO do not matter (so yEs and No will also be accepted).
对于每个测试用例,如果存在一个数组 a,使得对所有 i,bi 均为 a1,a2,…,a2i−1 的中位数,则输出一行 YES;否则输出 NO。YES 和 NO 的大小写不敏感(因此 yEs 和 No 也可被接受)。
输入输出样例
输入#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] will generate an OmkArray of [4], as the median of the first element is 4.
In the fourth case of the first sample, the array [3,2,5] will generate an OmkArray of [3,3], as the median of 3 is 3 and the median of 2,3,5 is 3.
In the fifth case of the first sample, the array [2,1,0,3,4,4,3] will generate an OmkArray of [2,1,2,3] as
- the median of 2 is 2
- the median of 0,1,2 is 1
- the median of 0,1,2,3,4 is 2
- and the median of 0,1,2,3,3,4,4 is 3.
In the second case of the second sample, the array [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], as
- the median of 1 is 1
- the median of 0,1,4 is 1
- the median of 0,1,3,4,5 is 3
- the median of −2,−2,0,1,3,4,5 is 1
- the median of −4,−2,−2,−2,0,1,3,4,5 is 0
- the median of −4,−4,−3,−2,−2,−2,0,1,3,4,5 is −2
- and the median of −4,−4,−3,−2,−2,−2,−1,0,1,3,4,5,5 is −1
For all cases where the answer is NO, it can be proven that it is impossible to find an array a such that b is the OmkArray of a.
在第一个样例的第二种情况中,数组 [4] 将生成 OmkArray [4],因为首个元素的中位数为 4。
在第一个样例的第四种情况中,数组 [3,2,5] 将生成 OmkArray [3,3],因为 3 的中位数为 3,而 2,3,5 的中位数为 3。
在第一个样例的第五种情况中,数组 [2,1,0,3,4,4,3] 将生成 OmkArray [2,1,2,3],因为:
- 2 的中位数为 2;
- 0,1,2 的中位数为 1;
- 0,1,2,3,4 的中位数为 2;
- 0,1,2,3,3,4,4 的中位数为 3。
在第二个样例的第二种情况中,数组 [1,0,4,3,5,−2,−2,−2,−4,−3,−4,−1,5] 将生成 OmkArray [1,1,3,1,0,−2,−1],因为:
- 1 的中位数为 1;
- 0,1,4 的中位数为 1;
- 0,1,3,4,5 的中位数为 3;
- −2,−2,0,1,3,4,5 的中位数为 1;
- −4,−2,−2,−2,0,1,3,4,5 的中位数为 0;
- −4,−4,−3,−2,−2,−2,0,1,3,4,5 的中位数为 −2;
- −4,−4,−3,−2,−2,−2,−1,0,1,3,4,5,5 的中位数为 −1。
对于所有答案为 NO 的情况,均可证明:不存在数组 a,使得 b 是 a 的 OmkArray。
输入解题思路,AI测评打分。不知道怎么写?