CF1416C.XOR Inverse

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:512MB

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=ai⊕xb_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 1≤i<j≤n1 \le i \lt j \le n and bi>bjb_i \gt 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,其构造规则如下:对所有从 11 到 nn 的 ii,令 bi=ai⊕xb_i = a_i \oplus x(其中 ⊕\oplus 表示按位异或运算)。

数组 bb 中的一个逆序对是指一对整数 (i,j)(i, j),满足 1≤i<j≤n1 \le i \lt j \le n 且 bi>bjb_i \gt b_j。

你需要选择 xx,使得数组 bb 中的逆序对数量最小。若存在多个满足条件的 xx,请输出其中最小的一个。

输入格式

First line contains a single integer nn (1≤n≤3⋅1051 \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 (0≤ai≤1090 \le a_i \le 10^9), where aia_i is the ii-th element of aa.

第一行包含一个整数 nn(1≤n≤3⋅1051 \le n \le 3 \cdot 10^5)—— 表示数组 aa 的元素个数。

第二行包含 nn 个以空格分隔的整数 a1a_1, a2a_2, ..., ana_n(0≤ai≤1090 \le a_i \le 10^9),其中 aia_i 是数组 aa 的第 ii 个元素。

输出格式

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]。该数组不含逆序对。

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

首页