CF1416C XOR Inverse
题目链接
CF1416C XOR Inverse
题目描述
You are given an array consisting of non-negative integers. You have to choose a non-negative integer and form a new array of size according to the following rule: for all from 1 to , denotes the operation bitwise XOR).
An inversion in the array is a pair of integers and such that and .
You should choose in such a way that the number of inversions in is minimized. If there are several options for - output the smallest one.
输入格式
First line contains a single integer the number of elements in .
Second line contains space-separated integers , where is the th element of .
输出格式
Output two integers: the minimum possible number of inversions in , and the minimum possible value of , which achieves those number of inversions.
题目翻译
给定长度为 的数列 ,请求出最小的整数 使 的 逆序对数最少,其中 是异或
输入格式
第一行 ,第二行
输出格式
两个数,逆序对数和
解题思路
01trie
建立一棵下标01trie,即每插入一个数,在每个节点记录该数的下标,可知每个节点中的下标都是递增的,对于一棵子树来说,其右子树的值都要大于左子树,现在要求的即为右子树中下标小于左子树的对数,进而求出该子树的逆序对数量,当 对应该位的值为 时,即左右子树交换位置,逆序对的个数为总的对数减去原逆序对的数量, 某一位为 当前仅当该位取 时的逆序对数量小于取 时的逆序对数量
- 时间复杂度:
代码
__EOF__

本文链接:https://www.cnblogs.com/zyyun/p/15979960.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角【推荐】一下。您的鼓励是博主的最大动力!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!