题库练习 XOR Inverse
← 上一题 下一题 →

A13866 | XOR Inverse

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

You are given an array $a$ consisting of $n$ non-negative integers. You have to choose a non-negative integer $x$ and form a new array $b$ of size $n$ according to the following rule: for all $i$ from $1$ to $n$ , $b_i = a_i \oplus x$ ( $\oplus$ denotes the operation [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR)).

An inversion in the $b$ array is a pair of integers $i$ and $j$ such that $1 \le i < j \le n$ and $b_i > b_j$ .

You should choose $x$ in such a way that the number of inversions in $b$ is minimized. If there are several options for $x$ — output the smallest one.
给你一个由 $n$ 个非负整数组成的数组 $a$ 。你必须选择一个非负整数 $x$ 并根据以下规则组成一个大小为 $n$ 的新数组 $b$ :对于从 $1$ 到 $n$ 的所有 $i$ , $b_i = a_i \oplus x$ ( $\oplus$ 表示操作 [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR))。

$b$ 数组中的反转是一对整数 $i$ 和 $j$ ,即 $1 \le i \lt j \le n$ 和 $b_i \gt b_j$ 。

在选择 $x$ 时,应尽量减少 $b$ 中的反转次数。如果 $x$ 有多个选项,则输出最小的一个。

输入格式

First line contains a single integer $n$ ( $1 \le n \le 3 \cdot 10^5$ ) — the number of elements in $a$ .

Second line contains $n$ space-separated integers $a_1$ , $a_2$ , ..., $a_n$ ( $0 \le a_i \le 10^9$ ), where $a_i$ is the $i$ -th element of $a$ .
第一行包含一个整数 $n$ ( $1 \le n \le 3 \cdot 10^5$ ) - $a$ 中的元素个数。

第二行包含 $n$ 个空格分隔的整数 $a_1$ , $a_2$ , ..., $a_n$ ( $0 \le a_i \le 10^9$ ),其中 $a_i$ 是 $a$ 的 $i$ -th 元素。

输出格式

Output two integers: the minimum possible number of inversions in $b$ , and the minimum possible value of $x$ , which achieves those number of inversions.
输出两个整数: $b$ 中可能的最小反转次数,以及实现这些反转次数的 $x$ 的最小值。

输入输出样例

输入 #1
4
0 1 3 2
输出 #1
1 0
输入 #2
9
10 7 9 10 7 5 5 3 5
输出 #2
4 14
输入 #3
3
8 10 3
输出 #3
0 8
C++ 编辑器
输入
输出