CF1601A.Array Elimination

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given array a1,a2,,ana_1, a_2, \ldots, a_n , consisting of non-negative integers.

Let's define operation of "elimination" with integer parameter kk ( 1kn1 \leq k \leq n ) as follows:

  • Choose kk distinct array indices 1i1<i2<<ikn1 \leq i_1 < i_2 < \ldots < i_k \le n .
  • Calculate x=ai1 & ai2 &  & aikx = a_{i_1} ~ \& ~ a_{i_2} ~ \& ~ \ldots ~ \& ~ a_{i_k} , where &\& denotes the bitwise AND operation (notes section contains formal definition).
  • Subtract xx from each of ai1,ai2,,aika_{i_1}, a_{i_2}, \ldots, a_{i_k} ; all other elements remain untouched.

Find all possible values of kk , such that it's possible to make all elements of array aa equal to 00 using a finite number of elimination operations with parameter kk . It can be proven that exists at least one possible kk for any array aa .

Note that you firstly choose kk and only after that perform elimination operations with value kk you've chosen initially.

输入格式

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

The first line of each test case contains one integer nn ( 1n2000001 \leq n \leq 200\,000 ) — the length of array aa .

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n ( 0ai<2300 \leq a_i < 2^{30} ) — array aa itself.

It's guaranteed that the sum of nn over all test cases doesn't exceed 200000200\,000 .

输出格式

For each test case, print all values kk , such that it's possible to make all elements of aa equal to 00 in a finite number of elimination operations with the given parameter kk .

Print them in increasing order.

输入输出样例

  • 输入#1

    5
    4
    4 4 4 4
    4
    13 7 25 19
    6
    3 5 3 1 7 1
    1
    1
    5
    0 0 0 0 0

    输出#1

    1 2 4
    1 2
    1
    1
    1 2 3 4 5

说明/提示

In the first test case:

  • If k=1k = 1 , we can make four elimination operations with sets of indices {1}\{1\} , {2}\{2\} , {3}\{3\} , {4}\{4\} . Since &\& of one element is equal to the element itself, then for each operation x=aix = a_i , so aix=aiai=0a_i - x = a_i - a_i = 0 .
  • If k=2k = 2 , we can make two elimination operations with, for example, sets of indices {1,3}\{1, 3\} and {2,4}\{2, 4\} : x=a1 & a3x = a_1 ~ \& ~ a_3 == a2 & a4a_2 ~ \& ~ a_4 == 4 & 4=44 ~ \& ~ 4 = 4 . For both operations x=4x = 4 , so after the first operation a1x=0a_1 - x = 0 and a3x=0a_3 - x = 0 , and after the second operation — a2x=0a_2 - x = 0 and a4x=0a_4 - x = 0 .
  • If k=3k = 3 , it's impossible to make all aia_i equal to 00 . After performing the first operation, we'll get three elements equal to 00 and one equal to 44 . After that, all elimination operations won't change anything, since at least one chosen element will always be equal to 00 .
  • If k=4k = 4 , we can make one operation with set {1,2,3,4}\{1, 2, 3, 4\} , because x=a1 & a2 & a3 & a4x = a_1 ~ \& ~ a_2 ~ \& ~ a_3 ~ \& ~ a_4 =4= 4 .

In the second test case, if k=2k = 2 then we can make the following elimination operations:

  • Operation with indices {1,3}\{1, 3\} : x=a1 & a3x = a_1 ~ \& ~ a_3 == 13 & 25=913 ~ \& ~ 25 = 9 . a1x=139=4a_1 - x = 13 - 9 = 4 and a3x=259=16a_3 - x = 25 - 9 = 16 . Array aa will become equal to [4,7,16,19][4, 7, 16, 19] .
  • Operation with indices {3,4}\{3, 4\} : x=a3 & a4x = a_3 ~ \& ~ a_4 == 16 & 19=1616 ~ \& ~ 19 = 16 . a3x=1616=0a_3 - x = 16 - 16 = 0 and a4x=1916=3a_4 - x = 19 - 16 = 3 . Array aa will become equal to [4,7,0,3][4, 7, 0, 3] .
  • Operation with indices {2,4}\{2, 4\} : x=a2 & a4x = a_2 ~ \& ~ a_4 == 7 & 3=37 ~ \& ~ 3 = 3 . a2x=73=4a_2 - x = 7 - 3 = 4 and a4x=33=0a_4 - x = 3 - 3 = 0 . Array aa will become equal to [4,4,0,0][4, 4, 0, 0] .
  • Operation with indices {1,2}\{1, 2\} : x=a1 & a2x = a_1 ~ \& ~ a_2 == 4 & 4=44 ~ \& ~ 4 = 4 . a1x=44=0a_1 - x = 4 - 4 = 0 and a2x=44=0a_2 - x = 4 - 4 = 0 . Array aa will become equal to [0,0,0,0][0, 0, 0, 0] .

Formal definition of bitwise AND:

Let's define bitwise AND ( &\& ) as follows. Suppose we have two non-negative integers xx and yy , let's look at their binary representations (possibly, with leading zeroes): xkx2x1x0x_k \dots x_2 x_1 x_0 and yky2y1y0y_k \dots y_2 y_1 y_0 . Here, xix_i is the ii -th bit of number xx , and yiy_i is the ii -th bit of number yy . Let r=x & yr = x ~ \& ~ y is a result of operation &\& on number xx and yy . Then binary representation of rr will be rkr2r1r0r_k \dots r_2 r_1 r_0 , where:

$$ r_i = \begin{cases} 1, ~ \text{if} ~ x_i = 1 ~ \text{and} ~ y_i = 1 \\ 0, ~ \text{if} ~ x_i = 0 ~ \text{or} ~ y_i = 0 \end{cases} $$
首页