CF1416C.XOR Inverse
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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, bi=ai⊕x (⊕ denotes the operation bitwise XOR).
An inversion in the b array is a pair of integers i and j such that 1≤i<j≤n and bi>bj.
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,令 bi=ai⊕x(其中 ⊕ 表示按位异或运算)。
数组 b 中的一个逆序对是指一对整数 (i,j),满足 1≤i<j≤n 且 bi>bj。
你需要选择 x,使得数组 b 中的逆序对数量最小。若存在多个满足条件的 x,请输出其中最小的一个。
输入格式
First line contains a single integer n (1≤n≤3⋅105) — the number of elements in a.
Second line contains n space-separated integers a1, a2, ..., an (0≤ai≤109), where ai is the i-th element of a.
第一行包含一个整数 n(1≤n≤3⋅105)—— 表示数组 a 的元素个数。
第二行包含 n 个以空格分隔的整数 a1, a2, ..., an(0≤ai≤109),其中 ai 是数组 a 的第 i 个元素。
输出格式
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
说明/提示
In the first sample it is optimal to leave the array as it is by choosing x=0.
In the second sample the selection of x=14 results in b: [4,9,7,4,9,11,11,13,11]. It has 4 inversions:
- i=2, j=3;
- i=2, j=4;
- i=3, j=4;
- i=8, j=9.
In the third sample the selection of x=8 results in b: [0,2,11]. It has no inversions.
在第一个样例中,选择 x=0 保持数组不变是最优的。
在第二个样例中,选择 x=14 得到数组 b: [4,9,7,4,9,11,11,13,11]。该数组包含 4 个逆序对:
- i=2, j=3;
- i=2, j=4;
- i=3, j=4;
- i=8, j=9。
在第三个样例中,选择 x=8 得到数组 b: [0,2,11]。该数组不含逆序对。
输入解题思路,AI测评打分。不知道怎么写?