可持续字典树 Perfect Security
题目大意:给你两个序列,第二个序列可以任意进行排列变换,然后由这两个序列一一异或得到答案序列,要求答案序列的字典序最小。
可持续字典树与第K大可持续线段树的区别主要在于每个节点上 ,它多了一个记录值。
因为线段树肯定是对区间处理,要+1的,但是字典树是对点处理,这两个值都要记录。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=3e5+;
int sum[N*][],son[N*][],x,n,tot,a[N];
void update(int last,int cur,int num,int pos){
int temp=!!(num&(<<pos));
sum[cur][temp]=sum[last][temp]+;
sum[cur][temp^]=sum[last][temp^];
son[cur][temp^]=son[last][temp^];
if(!pos) return;
update(son[last][temp],son[cur][temp]=++tot,num,pos-);
}
void query(int last,int cur,int num,int pos,int ans){
if(pos<) {printf("%d ",ans);return;}
int temp=!!(num&(<<pos));
if(sum[cur][temp]-sum[last][temp]>) --sum[cur][temp],query(son[last][temp],son[cur][temp],num,pos-,ans);
else --sum[cur][temp^],query(son[last][temp^],son[cur][temp^],num,pos-,ans|(<<pos));
}
int main(){
scanf("%d",&n);
for(int i=;i<=n;++i) scanf("%d",a+i);
scanf("%d",&x);
update(,++tot,x,);
for(int i=;i<=n;++i) {
scanf("%d",&x);
update((i-)*+,++tot,x,);
}
for(int i=;i<=n;++i) query(,(n-)*+,a[i],,);
puts("");
}
可持续字典树 Perfect Security的更多相关文章
- hdu4757 可持续字典树
Tree Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others)Total Sub ...
- Codeforces 948D Perfect Security(字典树)
题目链接:Perfect Security 题意:给出N个数代表密码,再给出N个数代表key.现在要将key组排序,使key组和密码组的亦或所形成的组字典序最小. 题解:要使密码组里面每个数都找到能使 ...
- Codeforces 948D Perfect Security 【01字典树】
<题目链接> 题目大意: 给定两个长度为n的序列,可以改变第二个序列中数的顺序,使得两个序列相同位置的数异或之后得到的新序列的字典序最小. 解题分析: 用01字典树来解决异或最值问题.因为 ...
- [CodeForces948D]Perfect Security(01字典树)
Description 题目链接 Solution 01字典树模板题,删除操作用个数组记录下就行了 Code #include <cstdio> #include <algorith ...
- 01Trie树 CF923C Perfect Security
CF923C Perfect Security 上下各n个数,求一种排列p,使上面的数i异或pi成为新的数i,求方案另字典序最小,输出该结果 01Trie树. 记录每个节点经过多少次. 每一次查询的时 ...
- 算法笔记--字典树(trie 树)&& ac自动机 && 可持久化trie
字典树 简介:字典树,又称单词查找树,Trie树,是一种树形结构,是哈希树的变种. 优点:利用字符串的公共前缀来减少查询时间,最大限度地减少无谓的字符串比较. 性质:根节点不包含字符,除根节点外每一个 ...
- Codeforces 948D Perfect Security
Perfect Security 题意:给你一个A[i]数组, 再给你一个B[i]数组, 现在用选取 B[i] 数组中的一个 去和 A[i] 数组里的一个元素去进行异或操作, B[i]数组的元素只能用 ...
- [LeetCode] Implement Trie (Prefix Tree) 实现字典树(前缀树)
Implement a trie with insert, search, and startsWith methods. Note:You may assume that all inputs ar ...
- Good Firewall(字典树 HDU4760)
Good Firewall Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
随机推荐
- Spring Boot中Spring data注解的使用
文章目录 Spring Data Annotations @Transactional @NoRepositoryBean @Param @Id @Transient @CreatedBy, @Las ...
- Libra白皮书解读
文章目录 Libra简介 Libra区块链 Libra货币和存储 Libra协会 Libra简介 Libra是facebook发起的一个区块链项目,其使命是建立一套简单的.无国界的货币和为数十亿人服务 ...
- c语言-----劫持系统03
1. 回顾 在前2节我们已经实现了劫持原理.函数指针等一些概念,下面进行系统劫持 2. 工具 vs2017 Detours 3. windows如何创建一个进程? (1)创建进程函数 CreatePr ...
- Oliver Twist
对于济贫院那些绅士们而言,贫民好吃懒做.贪得无厌.他们消耗的食物即是对教区最大的威胁. 绅士们的利益得不到满足时,孤儿们只能被驱之而后快,甚至被"加价出售". 然而,眼泪这种东西根 ...
- SVN 部署(基于 Linux)
1.通过 yum 命令安装 svnserve,命令如下: # 此命令会全自动安装svn服务器相关服务和依赖,安装完成会自动停止命令运行 yum -y install subversion # 若需查看 ...
- 一只简单的网络爬虫(基于linux C/C++)————主事件流程
该爬虫的主事件流程大致如下: 1.获取命令行参数,执行相应操作 2.读取配置文件,解析得到各种设置 3.载入各种模块 4.种子入队,开启DNS解析线程(原始队列不为空时解析) 5.创建epoll,开启 ...
- C#对象初始化器
1.对象初始化器 Student objStu2 = new Student() { StudentId=, //属性之间使用","分隔 StudentName="小明& ...
- G - Island Transport 网络流
题目: In the vast waters far far away, there are many islands. People are living on the islands, and a ...
- Zabbix 添加vmware esxi监控
1) Import the provided template. - TEMPLATE.VMWARE_ESXi_6.0_CIM.xml 2) Install Dependencies: # yum - ...
- input唤起键盘影响移动端底部fixed定位
主要代码如下: public docmHeight = document.documentElement.clientHeight || document.body.clientHeight; // ...