1775B.md (2884B)
1 Source: https://codeforces.com/problemset/problem/1775/B 2 3 B. Gardener and the Array 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 The gardener Kazimir Kazimirovich has an array of $n$ integers $c_1, c_2, \dots, c_n$. 22 23 He wants to check if there are two different subsequences $a$ and $b$ of the original array, for which $f(a) = f(b)$, where $f(x)$ is the [bitwise OR](https://en.wikipedia.org/wiki/Bitwise_operation#OR) of all of the numbers in the sequence $x$. 24 25 A sequence $q$ is a subsequence of $p$ if $q$ can be obtained from $p$ by deleting several (possibly none or all) elements. 26 27 Two subsequences are considered different if the sets of indexes of their elements in the original sequence are different, that is, the values of the elements are not considered when comparing the subsequences. 28 29  30 31 Input 32 33 Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^5$). The description of the test cases follows. 34 35 The first line of each test case contains one integer $n$ ($1 \le n \le 10^5$) — the size of the array $c$. 36 37 The description of the array $c$ in this problem is given implicitly to speed up input. 38 39 The $(i + 1)$-st of the following $n$ lines of the test case begins with an integer $k_i$ ($1 \le k_i \le 10^5$) — the number of set bits in the number $c_i$. Next follow $k_i$ distinct integers $p_{i, 1}, p_{i, 2}, \dots, p_{i, k_i}$ ($1 \le p_i \le 2 \cdot 10^5$) —the numbers of bits that are set to one in number $c_i$. In other words, $c_i = 2^{p_{i, 1}} + 2^{p_{i, 2}} + \ldots + 2^{p_{i, k_i}}$. 40 41 It is guaranteed that the total sum of $k_i$ in all tests does not exceed $10^5$. 42 43 Output 44 45 For each set of input, print "Yes" if there exist two different subsequences for which $f(a) = f(b)$, and "No" otherwise. 46 47 You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses. 48 49 Example 50 51 Input 52 53 ``` 54 5 55 56 3 57 58 2 1 5 59 60 2 2 4 61 62 2 2 3 63 64 2 65 66 2 1 2 67 68 1 2 69 70 4 71 72 3 1 2 4 73 74 2 2 4 75 76 4 1 2 5 6 77 78 2 2 5 79 80 5 81 82 3 3 1 2 83 84 3 2 5 3 85 86 5 7 2 3 1 4 87 88 5 1 2 6 3 5 89 90 3 2 6 3 91 92 2 93 94 1 1 95 96 1 2 97 ``` 98 99 Output 100 101 ``` 102 No 103 Yes 104 Yes 105 Yes 106 No 107 ``` 108 109 Note 110 111 It can be proven that in the first test case there are no two different subsequences $a$ and $b$ for which $f(a) = f(b)$. 112 113 In the second test case, one of the possible answers are following subsequences: the subsequence $a$ formed by the element at position $1$, and the subsequence $b$ formed by the elements at positions $1$ and $2$. 114 115 In the third test case, one of the possible answers are following subsequences: the subsequence $a$ formed by elements at positions $1$, $2$, $3$ and $4$, and the subsequence $b$ formed by elements at positions $2$, $3$ and $4$.