CF1926D.Vlad and Division

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Vladislav has nn non-negative integers, and he wants to divide all of them into several groups so that in any group, any pair of numbers does not have matching bit values among bits from 11-st to 3131-st bit (i.e., considering the 3131 least significant bits of the binary representation).

For an integer kk, let k2(i)k_2(i) denote the ii-th bit in its binary representation (from right to left, indexing from 1). For example, if k=43k=43, since 43=101011243=101011_2, then 432(1)=143_2(1)=1, 432(2)=143_2(2)=1, 432(3)=043_2(3)=0, 432(4)=143_2(4)=1, 432(5)=043_2(5)=0, 432(6)=143_2(6)=1, 432(7)=043_2(7)=0, 432(8)=0,…,432(31)=043_2(8)=0, \dots, 43_2(31)=0.

Formally, for any two numbers xx and yy in the same group, the condition x2(i)≠y2(i)x_2(i) \neq y_2(i) must hold for all 1≤i<321 \leq i \lt 32.

What is the minimum number of groups Vlad needs to achieve his goal? Each number must fall into exactly one group.

弗拉迪斯拉夫有 nn 个非负整数,他希望将所有这些数划分为若干组,使得在任意一组中,任意两个数在二进制表示的第 11 位至第 3131 位(即最低的 3131 个二进制位)上均无相同的比特值。

对任意整数 kk,记 k2(i)k_2(i) 表示其二进制表示中从右向左数第 ii 位的值(位索引从 11 开始)。例如,若 k=43k = 43,由于 43=101011243 = 101011_2,则有 432(1)=143_2(1) = 1,432(2)=143_2(2) = 1,432(3)=043_2(3) = 0,432(4)=143_2(4) = 1,432(5)=043_2(5) = 0,432(6)=143_2(6) = 1,432(7)=043_2(7) = 0,432(8)=0,…,432(31)=043_2(8) = 0, \dots, 43_2(31) = 0。

形式化地说,对同一组内的任意两个数 xx 和 yy,必须满足:对所有 1≤i<321 \leq i < 32,均有 x2(i)≠y2(i)x_2(i) \neq y_2(i)。

为达成目标,弗拉迪斯拉夫最少需要多少个组?每个数必须且仅能属于一个组。

输入格式

The first line contains a single integer tt (1≤t≤1041 \leq t \leq 10^4) — the number of test cases.

The first line of each test case contains a single integer nn (1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5) — the total number of integers.

The second line of each test case contains nn given integers a1,…,ana_1, \ldots, a_n (0≤aj<2310 \leq a_j \lt 2^{31}).

The sum of nn over all test cases in a test does not exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \leq t \leq 10^4)——测试用例的数量。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5)——整数的总个数。

每个测试用例的第二行包含 nn 个给定的整数 a1,…,ana_1, \ldots, a_n(0≤aj<2310 \leq a_j \lt 2^{31})。

所有测试用例中的 nn 之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output a single integer — the minimum number of groups required to satisfy the condition.

对于每个测试用例,输出一个整数——满足条件所需的最少组数。

输入输出样例

  • 输入#1

    9
    4
    1 4 3 4
    2
    0 2147483647
    5
    476319172 261956880 2136179468 1671164475 1885526767
    3
    1335890506 811593141 1128223362
    4
    688873446 627404104 1520079543 1458610201
    4
    61545621 2085938026 1269342732 1430258575
    4
    0 0 2147483647 2147483647
    3
    0 0 2147483647
    8
    1858058912 289424735 1858058912 2024818580 1858058912 289424735 122665067 289424735

    输出#1

    4
    1
    3
    2
    2
    3
    2
    2
    4

说明/提示

In the first test case, any two numbers have the same last 3131 bits, so we need to place each number in its own group.

In the second test case, a1=00000000000000000000000000000002a_1=0000000000000000000000000000000_2, a2=11111111111111111111111111111112a_2=1111111111111111111111111111111_2 so they can be placed in the same group because a1(i)≠a2(i)a_1(i) \ne a_2(i) for each ii between 11 and 3131, inclusive.

在第一个测试用例中,任意两个数的最低 3131 位都相同,因此我们需要将每个数单独分到一个组中。

在第二个测试用例中,a1=00000000000000000000000000000002a_1=0000000000000000000000000000000_2,a2=11111111111111111111111111111112a_2=1111111111111111111111111111111_2,因此它们可以被分到同一组中,因为对每个 ii(1≤i≤311 \le i \le 31),均有 a1(i)≠a2(i)a_1(i) \ne a_2(i)。

输入解题思路,AI测评打分。不知道怎么写?

首页