CF1416C.XOR Inverse

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given an array aa consisting of nn non-negative integers. You have to choose a non-negative integer xx and form a new array bb of size nn according to the following rule: for all ii from 11 to nn , bi=aixb_i = a_i \oplus x ( \oplus denotes the operation bitwise XOR).

An inversion in the bb array is a pair of integers ii and jj such that 1i<jn1 \le i < j \le n and bi>bjb_i > b_j .

You should choose xx in such a way that the number of inversions in bb is minimized. If there are several options for xx — output the smallest one.
给你一个由 nn 个非负整数组成的数组 aa 。你必须选择一个非负整数 xx 并根据以下规则组成一个大小为 nn 的新数组 bb :对于从 11nn 的所有 ii , bi=aixb_i = a_i \oplus x\oplus 表示操作 bitwise XOR)。

bb 数组中的反转是一对整数 iijj ,即 1i<jn1 \le i \lt j \le nbi>bjb_i \gt b_j

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

输入格式

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

Second line contains nn space-separated integers a1a_1 , a2a_2 , ..., ana_n ( 0ai1090 \le a_i \le 10^9 ), where aia_i is the ii -th element of aa .
第一行包含一个整数 nn ( 1n31051 \le n \le 3 \cdot 10^5 ) - aa 中的元素个数。

第二行包含 nn 个空格分隔的整数 a1a_1 , a2a_2 , ..., ana_n ( 0ai1090 \le a_i \le 10^9 ),其中 aia_iaaii -th 元素。

输出格式

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

输入输出样例

  • 输入#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

说明/提示

In the first sample it is optimal to leave the array as it is by choosing x=0x = 0 .

In the second sample the selection of x=14x = 14 results in bb : [4,9,7,4,9,11,11,13,11][4, 9, 7, 4, 9, 11, 11, 13, 11] . It has 44 inversions:

  • i=2i = 2 , j=3j = 3 ;
  • i=2i = 2 , j=4j = 4 ;
  • i=3i = 3 , j=4j = 4 ;
  • i=8i = 8 , j=9j = 9 .

In the third sample the selection of x=8x = 8 results in bb : [0,2,11][0, 2, 11] . It has no inversions.
在第一个样本中,选择 x=0x = 0 是保持数组原样的最佳选择。

在第二个样本中,选择 x=14x = 14 的结果是 bb[4,9,7,4,9,11,11,13,11][4, 9, 7, 4, 9, 11, 11, 13, 11] .反转次数为 44

  • i=2i = 2 , j=3j = 3 ;
  • i=2i = 2 , j=4j = 4 ;
  • i=3i = 3 , j=4j = 4 ;
  • i=8i = 8 , j=9j = 9 .

在第三个样本中,选择 x=8x = 8 的结果是 bb[0,2,11][0, 2, 11] .它没有倒位。

首页