可持续字典树 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 ...
随机推荐
- 关于CompletableFuture的一切,看这篇文章就够了
文章目录 CompletableFuture作为Future使用 异步执行code 组合Futures thenApply() 和 thenCompose()的区别 并行执行任务 异常处理 java中 ...
- MySQL5.7 并行复制
MySQL5.7 并行复制 1.缘由: 某天看到主从复制延时的告警有点频繁,就想着是不是彻底可以解决一下. 一般主从复制,有三个线程参与,都是单线程:Binlog Dump(主) ----->I ...
- APP路由还能这样玩
本文主要讲述一种设计思路,组件化架构市面上已经有很多大厂成熟的方案,但是在组件化过程中,偶尔会遇到2个独立业务子模块间没有相互引用,也需要能直接调用对方的功能,因此我想到通过方法路由来解决,如果还有疑 ...
- sphinx的使用
1.下载地址 http://sphinxsearch.com/downloads/release/ 2.将其解压到D:\sphinx,并在D:\sphinx下新建目录data(用来存放索引文件)与lo ...
- 现代软件工程讲义 如何提出靠谱的项目建议 NABCD
互联网时代对于创新者来说, 既是一个伟大的时代, 又是一个糟糕的时代. 你有很多机会做出影响世界的产品, 但是, 似乎任何想法都被别人想到过了, 做出来了, 上市了, 移植到各种平台上去了- 那么 ...
- 【阅读笔记】Ranking Relevance in Yahoo Search (二)—— maching learned ranking
3. MACHINE LEARNED RANKING 1) 完全使用不好的数据去训练模型不可行,因为负面结果不可能覆盖到所有方面: 2) 搜索可以看做是个二分问题,在此实验中,我们使用gradient ...
- 数学--数论--hdu 5878 I Count Two Three(二分)
I will show you the most popular board game in the Shanghai Ingress Resistance Team. It all started ...
- [NOI 2020 Online] 入门组T1 文具采购(洛谷 P6188)题解
原题传送门 题目部分:(来自于考试题面,经整理) [题目描述] 小明的班上共有 n 元班费,同学们准备使用班费集体购买 3 种物品: 1.圆规,每个 7 元. 2.笔,每支 4 元. 3.笔记本,每本 ...
- Java——接口相关知识
1.接口用interface来声明 //定义一个动物接口 public interface Animal{ public void eat(); public void travel(); } 2.接 ...
- Spring杂谈 | Spring中的AutowireCandidateResolver
接口定义 用于推断一个特定的beanDefinition是否能作为指定依赖的候选者的策略接口 public interface AutowireCandidateResolver { // 默认情况下 ...