CF1446C.Xor Tree

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

For a given sequence of distinct non-negative integers (b1,b2,…,bk)(b_1, b_2, \dots, b_k) we determine if it is good in the following way:

  • Consider a graph on kk nodes, with numbers from b1b_1 to bkb_k written on them.
  • For every ii from 11 to kk: find such jj (1≤j≤k1 \le j \le k, j≠ij\neq i), for which (bi⊕bj)(b_i \oplus b_j) is the smallest among all such jj, where ⊕\oplus denotes the operation of bitwise XOR (https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Next, draw an undirected edge between vertices with numbers bib_i and bjb_j in this graph.
  • We say that the sequence is good if and only if the resulting graph forms a tree (is connected and doesn't have any simple cycles).

It is possible that for some numbers bib_i and bjb_j, you will try to add the edge between them twice. Nevertheless, you will add this edge only once.

You can find an example below (the picture corresponding to the first test case).

Sequence (0,1,5,2,6)(0, 1, 5, 2, 6) is not good as we cannot reach 11 from 55.

However, sequence (0,1,5,2)(0, 1, 5, 2) is good.

You are given a sequence (a1,a2,…,an)(a_1, a_2, \dots, a_n) of distinct non-negative integers. You would like to remove some of the elements (possibly none) to make the remaining sequence good. What is the minimum possible number of removals required to achieve this goal?

It can be shown that for any sequence, we can remove some number of elements, leaving at least 22, so that the remaining sequence is good.

对于给定的一个由互不相同的非负整数构成的序列 (b1,b2,…,bk)(b_1, b_2, \dots, b_k),我们按如下方式判断它是否为“好序列”(good):

  • 构造一个包含 kk 个节点的图,各节点上分别标有数字 b1b_1 到 bkb_k;
  • 对每个 ii(1≤i≤k1 \le i \le k):找出满足 1≤j≤k1 \le j \le k 且 j≠ij \ne i 的下标 jj,使得 (bi⊕bj)(b_i \oplus b_j) 在所有这样的 jj 中取最小值(其中 ⊕\oplus 表示按位异或运算(https://en.wikipedia.org/wiki/Bitwise_operation#XOR))。然后,在标有数字 bib_i 和 bjb_j 的两个顶点之间连一条无向边;
  • 当且仅当最终得到的图是一棵树(即连通且不含简单环)时,称该序列为“好序列”。

注意:对某些 bib_i 和 bjb_j,可能在构造过程中尝试两次连接同一对顶点。但此时该边仅被添加一次。

下方提供了一个示例(对应第一个测试用例的图示):

序列 (0,1,5,2,6)(0, 1, 5, 2, 6) 不是好序列,因为从 55 无法到达 11;

而序列 (0,1,5,2)(0, 1, 5, 2) 是好序列。

现给你一个由互不相同的非负整数构成的序列 (a1,a2,…,an)(a_1, a_2, \dots, a_n)。你希望从中删除若干元素(可以不删),使得剩余元素构成的子序列是好序列。问:达成此目标所需的最少删除次数是多少?

可以证明:对任意序列,总可以通过删除若干元素,使剩余元素至少为 22 个,且构成好序列。

输入格式

The first line contains a single integer nn (2≤n≤200,0002 \le n \le 200,000) — length of the sequence.

The second line contains nn distinct non-negative integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤1090 \le a_i \le 10^9) — the elements of the sequence.

第一行包含一个整数 nn(2≤n≤200,0002 \le n \le 200{,}000)——序列的长度。

第二行包含 nn 个互不相同的非负整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai≤1090 \le a_i \le 10^9)——序列的元素。

输出格式

You should output exactly one integer — the minimum possible number of elements to remove in order to make the remaining sequence good.

你应该输出一个整数——为使剩余序列成为“好序列”所需删除的最少元素个数。

输入输出样例

  • 输入#1

    5
    0 1 5 2 6

    输出#1

    1
  • 输入#2

    7
    6 9 8 7 3 5 2

    输出#2

    2

说明/提示

Note that numbers which you remove don't impact the procedure of telling whether the resulting sequence is good.

It is possible that for some numbers bib_i and bjb_j, you will try to add the edge between them twice. Nevertheless, you will add this edge only once.

注意,你删除的数字不会影响判断剩余序列是否为“好序列”的过程。

对于某些数字 bib_i 和 bjb_j,你可能会尝试两次添加它们之间的边;但该边仅会被添加一次。

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

首页