[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的路向下走即可 # ...
随机推荐
- display详细说明
display:block,inline,inline-block区别 display:block就是将元素显示为块级元素. block元素的特点是: 总是在新行上开始: 高度,行高以及顶和底边距都可 ...
- 什么叫erp系统
一般来说,erp系统是一个以会计(此处的会计是指管理会计)为核心的信息系统,用来识别和规划企业资源, 从而获取客户订单, 完成加工和交付,最后得到客户付款,最终获得收入和利润. 实际上, erp 系统 ...
- 织梦上传webp格式图片
织梦cms如何添加其他格式的图片呢? 这里以webp为类来实现一下如何让织梦支持webp 1.修改系统设置让织梦(dede)支持该图片格式,比如:webp(新图片格式) 系统->系统基本参数-& ...
- (四)JavaScript之[break和continue]与[typeof、null、undefined]
7].break和continue /** * JavaScript 的break和continue语句 * break 跳出switch()语句 * break 用于跳出循环 * continue ...
- C#实现屏幕指定区域截屏
//string Opath = @"C:/Picture"; //if (Opath.Substring(Opath.Length - 1, 1) != @ ...
- Linux改变文件属性与权限
chgrp:改变文件所属用户组 chown:改变文件所有组 chmod:改变文件的权限 一.chgrp(change group的简称) 修改文件所属组:eg:chgrp users install. ...
- CentOS7下SSH服务学习笔记
测试环境: [root@nmserver-7 ~]# uname -aLinux nmserver-7.test.com 3.10.0-514.el7.centos.plus.i686 #1 SMP ...
- Object-C 语法 字符串 数组 字典 和常用函数 学习笔记
字符串 //取子字符串 NSString *str1=@"今天的猪肉真贵,200块一斤"; NSString *sub1=[str1 substringFromIndex:4]; ...
- Leetcode 78. Subsets (backtracking) 90 subset
using prev class Solution { List<List<Integer>> res = new ArrayList<List<Integer&g ...
- IOS http协议 总结
HTTP协议1.面试题常见:聊一下HTTP协议(协议的完整的通信过程) ============================================================ 一.一 ...