1973B.md (2227B)
1 Source: https://codeforces.com/problemset/problem/1973/B 2 3 B. Cat, Fox and the Lonely 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 Today, Cat and Fox found an array $a$ consisting of $n$ non-negative integers. 22 23 Define the loneliness of $a$ as the smallest positive integer $k$ ($1 \le k \le n$) such that for any two positive integers $i$ and $j$ ($1 \leq i, j \leq n - k +1$), the following holds: $$a_i | a_{i+1} | \ldots | a_{i+k-1} = a_j | a_{j+1} | \ldots | a_{j+k-1},$$ where $x | y$ denotes the [bitwise OR](https://en.wikipedia.org/wiki/Bitwise_operation#OR) of $x$ and $y$. In other words, for every $k$ consecutive elements, their bitwise OR should be the same. Note that the loneliness of $a$ is well-defined, because for $k = n$ the condition is satisfied. 24 25 Cat and Fox want to know how lonely the array $a$ is. Help them calculate the loneliness of the found array. 26 27 Input 28 29 Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4 $) — the number of test cases. The description of the test cases follows. 30 31 The first line of each test case contains one integer $n$ ($1 \leq n \leq 10^5$) — the length of the array $a$. 32 33 The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_i \lt 2^{20}$) — the elements of the array. 34 35 It is guaranteed that the sum of $n$ over all test cases doesn't exceed $10^5$. 36 37 Output 38 39 For each test case, print one integer — the loneliness of the given array. 40 41 Example 42 43 Input 44 45 ``` 46 7 47 48 1 49 50 0 51 52 3 53 54 2 2 2 55 56 3 57 58 1 0 2 59 60 5 61 62 3 0 1 4 2 63 64 5 65 66 2 0 4 0 2 67 68 7 69 70 0 0 0 0 1 2 4 71 72 8 73 74 0 1 3 2 2 1 0 3 75 ``` 76 77 Output 78 79 ``` 80 1 81 1 82 3 83 4 84 4 85 7 86 3 87 ``` 88 89 Note 90 91 In the first example, the loneliness of an array with a single element is always $1$, so the answer is $1$. 92 93 In the second example, the OR of each subarray of length $k = 1$ is $2$, so the loneliness of the whole array is $1$. 94 95 In the seventh example, it's true that $(0 | 1 | 3) = (1 | 3 | 2) = (3 | 2 | 2) = (2 | 2 | 1) = (2 | 1 | 0) = (1 | 0 | 3) = 3$, so the condition is satisfied for $k = 3$. We can verify that the condition is not true for any smaller $k$, so the answer is indeed $3$.