310436: CF1833C. Vlad Building Beautiful Array

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:7 Solved:0

Description

C. Vlad Building Beautiful Arraytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Vlad was given an array $a$ of $n$ positive integers. Now he wants to build a beautiful array $b$ of length $n$ from it.

Vlad considers an array beautiful if all the numbers in it are positive and have the same parity. That is, all numbers in the beautiful array are greater than zero and are either all even or all odd.

To build the array $b$, Vlad can assign each $b_i$ either the value $a_i$ or $a_i - a_j$, where any $j$ from $1$ to $n$ can be chosen.

To avoid trying to do the impossible, Vlad asks you to determine whether it is possible to build a beautiful array $b$ of length $n$ using his array $a$.

Input

The first line of input contains an integer $t$ ($1 \le t \le 10^4$) — the number of test cases.

Then follow the descriptions of the test cases.

The first line of each case contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the length of the array $a$.

The second line of each case contains $n$ positive integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the elements of the array $a$.

It is guaranteed that the sum of $n$ over all cases does not exceed $2 \cdot 10^5$.

Output

Output $t$ strings, each of which is the answer to the corresponding test case. As the answer, output "YES" if Vlad can build a beautiful array $b$, and "NO" otherwise.

You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).

ExampleInput
7
5
2 6 8 4 3
5
1 4 7 6 9
4
2 6 4 10
7
5 29 13 9 10000001 11 3
5
2 1 2 4 2
5
2 4 5 4 3
4
2 5 5 4
Output
NO
YES
YES
YES
YES
NO
NO

Input

题意翻译

我们称一个正整数序列是好的,当且仅当序列中所有的元素要么全是奇数,要么全是偶数。**形式化的**,对于长度为 $n$ 的正整数序列 $a_1,a_2,\dots,a_n$,若 $a_1\equiv a_2\equiv\dots\equiv a_n\pmod2$,那么它是好的。 [cff]:0102 现在你有一个长度为 $n$ 的正整数序列 $a$,你要以此来构造一个好的长度为 $n$ 的正整数序列 $b$,要求 $b_i$ 要么等于 $a_i$,要么等于 $a_i-a_j$,其中 $1\le j\le n$。 多组询问,对于每一组询问,请确定能否构造满足要求的正整数序列 $b$。 $1\le t\le10^4,1\le\sum n\le2\times10^5,1\le a_i\le10^9$。

Output

题目大意:
弗拉德有一个由n个正整数组成的数组a。现在他想从数组a构建一个长度为n的“美丽”数组b。

弗拉德认为一个数组是“美丽”的,如果数组中的所有数字都是正数且具有相同的奇偶性。也就是说,“美丽”数组中的所有数字都大于零,要么都是偶数,要么都是奇数。

为了构建数组b,弗拉德可以给每个b_i赋值为a_i或者a_i - a_j,其中j可以从1到n中任意选择。

为了避免尝试不可能的事情,弗拉德要求你确定是否可以用他的数组a构建一个长度为n的“美丽”数组b。

输入数据格式:
第一行输入包含一个整数t(1≤t≤10^4)——测试用例的数量。

接下来是t个测试用例的描述。
每个测试用例的第一行包含一个整数n(1≤n≤2×10^5)——数组a的长度。
第二行包含n个正整数a_1, a_2, …, a_n(1≤a_i≤10^9)——数组a的元素。
保证所有测试用例的n之和不超过2×10^5。

输出数据格式:
输出t个字符串,每个字符串是对应测试用例的答案。如果弗拉德可以构建一个“美丽”的数组b,则输出“YES”,否则输出“NO”。

示例输入输出:
```
Input
7
5
2 6 8 4 3
5
1 4 7 6 9
4
2 6 4 10
7
5 29 13 9 10000001 11 3
5
2 1 2 4 2
5
2 4 5 4 3
4
2 5 5 4

Output
NO
YES
YES
YES
YES
NO
NO
```
题目大意: 弗拉德有一个由n个正整数组成的数组a。现在他想从数组a构建一个长度为n的“美丽”数组b。 弗拉德认为一个数组是“美丽”的,如果数组中的所有数字都是正数且具有相同的奇偶性。也就是说,“美丽”数组中的所有数字都大于零,要么都是偶数,要么都是奇数。 为了构建数组b,弗拉德可以给每个b_i赋值为a_i或者a_i - a_j,其中j可以从1到n中任意选择。 为了避免尝试不可能的事情,弗拉德要求你确定是否可以用他的数组a构建一个长度为n的“美丽”数组b。 输入数据格式: 第一行输入包含一个整数t(1≤t≤10^4)——测试用例的数量。 接下来是t个测试用例的描述。 每个测试用例的第一行包含一个整数n(1≤n≤2×10^5)——数组a的长度。 第二行包含n个正整数a_1, a_2, …, a_n(1≤a_i≤10^9)——数组a的元素。 保证所有测试用例的n之和不超过2×10^5。 输出数据格式: 输出t个字符串,每个字符串是对应测试用例的答案。如果弗拉德可以构建一个“美丽”的数组b,则输出“YES”,否则输出“NO”。 示例输入输出: ``` Input 7 5 2 6 8 4 3 5 1 4 7 6 9 4 2 6 4 10 7 5 29 13 9 10000001 11 3 5 2 1 2 4 2 5 2 4 5 4 3 4 2 5 5 4 Output NO YES YES YES YES NO NO ```

加入题单

上一题 下一题 算法标签: