[CodeForces948D]Perfect Security(01字典树)
Description
Solution
01字典树模板题,删除操作用个数组记录下就行了
Code
#include <cstdio>
#include <algorithm>
#include <cmath>
int n,T[9000010][2],v[9000010],A[300010],num[9000010],rt=1,B[300010];
inline int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
void Insert(int x,int id){
int u=0,op;
for(int i=30;i>=0;--i){
op=((x&(1<<i))!=0);
if(!T[u][op]) T[u][op]=rt++;
u=T[u][op];
num[u]++;
}
v[u]=id;
}
void del(int x){
int u=0,op;
for(int i=30;i>=0;--i){
op=((x&(1<<i))!=0);
u=T[u][op];
num[u]--;
}
}
int get(int x){
int u=0,op;
for(int i=30;i>=0;--i){
op=((x&(1<<i))!=0);
if(T[u][op]&&num[T[u][op]]) u=T[u][op];
else u=T[u][op^1];
}
del(A[v[u]]);
return x^A[v[u]];
}
int main(){
n=read();
for(int i=1;i<=n;++i) B[i]=read();
for(int i=1;i<=n;++i) Insert(A[i]=read(),i);
for(int i=1;i<=n;++i) printf("%d ",get(B[i]));
return 0;
}
[CodeForces948D]Perfect Security(01字典树)的更多相关文章
- Codeforces 948D Perfect Security 【01字典树】
<题目链接> 题目大意: 给定两个长度为n的序列,可以改变第二个序列中数的顺序,使得两个序列相同位置的数异或之后得到的新序列的字典序最小. 解题分析: 用01字典树来解决异或最值问题.因为 ...
- Chip Factory---hdu5536(异或值最大,01字典树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题意:有一个数组a[], 包含n个数,从n个数中找到三个数使得 (a[i]+a[j])⊕a[k] ...
- Xor Sum---hdu4825(01字典树模板)
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4825 题意:有n个数m个查找,每个查找有一个数x, 从序列中找到一个数y,使得x异或y最大 ...
- Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树
A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...
- hdu5296 01字典树
根据二进制建一棵01字典树,每个节点的答案等于左节点0的个数 * 右节点1的个数 * 2,遍历整棵树就能得到答案. AC代码: #include<cstdio> using namespa ...
- Choosing The Commander CodeForces - 817E (01字典树+思维)
As you might remember from the previous round, Vova is currently playing a strategic game known as R ...
- hdu-4825(01字典树)
题意:中文题意 解题思路:01字典树板子题 代码: #include<iostream> #include<algorithm> #include<cstdio> ...
- 【cf842D】Vitya and Strange Lesson(01字典树)
D. Vitya and Strange Lesson 题意 数列里有n个数,m次操作,每次给x,让n个数都异或上x.并输出数列的mex值. 题解 01字典树保存每个节点下面有几个数,然后当前总异或的 ...
- hdu 4825 && acdream 1063 01字典树异或问题
题意: 给一个集合,多次询问,每次给一个k,问你集合和k异或结果最大的哪个 题解: 经典的01字典树问题,学习一哈. 把一个数字看成32位的01串,然后查找异或的时候不断的沿着^为1的路向下走即可 # ...
随机推荐
- mybase修改内部文件免费使用
关于mybase的介绍就不多说了,下载后一般只有30天的使用期限.以下方法可以无限次使用该软件(当然,每隔一个周期就需要修改myBase.ini) 原文博客详见:https://www.cnblogs ...
- python3 爬虫笔记(一)beautiful_soup
很多人学习python,爬虫入门,在python爬虫中,有很多库供开发使用. 用于请求的urllib(python3)和request基本库,xpath,beautiful soup,pyquery这 ...
- C++学习之继承中的成员访问控制
由基类到派生类的过程中,在派生类里如何访问基类成员,以及派生类对象如何访问基类成员,是根据派生类在从基类派生时是以什么方式进行的派生:public.protect或者private.下面说一下在这三种 ...
- IOS 九宫格算法
@interface ViewController () @property (nonatomic,strong) NSArray *apps; //获取.plist数据 @end @implemen ...
- C#自制png转ico图标工具
此项目基于.net framework 4.0 只需把图片拖拽到窗口内,自动转换生成ico图标,在png文件同级目录下. /// /// 实现代码: 转换Image为Icon /// ///要转换为图 ...
- Spring boot 实现高吞吐量异步处理(适用于高并发场景)
技术要点 org.springframework.web.context.request.async.DeferredResult<T> 示例如下: 1. 新建Maven项目 asy ...
- linux flushing file system caches
We may drop the file system caches on Linux to free up memory for applications. Kernels 2.6.16 and n ...
- C# unchecked运算符
一.C# unchecked运算符 unchecked运算符用于取消整型算术运算和转换的溢出检查. 二.提示 默认情况下,都是unchecked选项.因此,只有在需要把几个未检查的代码行放在一个明确标 ...
- 2、SpringBoot------数据转换
开发工具:STS 代码下载链接:https://github.com/theIndoorTrain/Springboot/tree/083bb312526653d27ca56abf4f586e097c ...
- postgresql 免安装版使用
免安装版 postgresql 使用 1.首先使用 initdb 初始化数据目录 initdb --pgdata=data --encoding=UTF8 --locale=C 2.启动 postgr ...