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字典树)的更多相关文章

  1. Codeforces 948D Perfect Security 【01字典树】

    <题目链接> 题目大意: 给定两个长度为n的序列,可以改变第二个序列中数的顺序,使得两个序列相同位置的数异或之后得到的新序列的字典序最小. 解题分析: 用01字典树来解决异或最值问题.因为 ...

  2. Chip Factory---hdu5536(异或值最大,01字典树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题意:有一个数组a[], 包含n个数,从n个数中找到三个数使得 (a[i]+a[j])⊕a[k] ...

  3. Xor Sum---hdu4825(01字典树模板)

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4825 题意:有n个数m个查找,每个查找有一个数x, 从序列中找到一个数y,使得x异或y最大 ...

  4. Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树

    A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...

  5. hdu5296 01字典树

    根据二进制建一棵01字典树,每个节点的答案等于左节点0的个数 * 右节点1的个数 * 2,遍历整棵树就能得到答案. AC代码: #include<cstdio> using namespa ...

  6. Choosing The Commander CodeForces - 817E (01字典树+思维)

    As you might remember from the previous round, Vova is currently playing a strategic game known as R ...

  7. hdu-4825(01字典树)

    题意:中文题意 解题思路:01字典树板子题 代码: #include<iostream> #include<algorithm> #include<cstdio> ...

  8. 【cf842D】Vitya and Strange Lesson(01字典树)

    D. Vitya and Strange Lesson 题意 数列里有n个数,m次操作,每次给x,让n个数都异或上x.并输出数列的mex值. 题解 01字典树保存每个节点下面有几个数,然后当前总异或的 ...

  9. hdu 4825 && acdream 1063 01字典树异或问题

    题意: 给一个集合,多次询问,每次给一个k,问你集合和k异或结果最大的哪个 题解: 经典的01字典树问题,学习一哈. 把一个数字看成32位的01串,然后查找异或的时候不断的沿着^为1的路向下走即可 # ...

随机推荐

  1. The eleventh day

    What's the damage? Thanks so much for fixing the break on my car . What's the damage for the work yo ...

  2. 工作中遇到的vscode配合eslint完成保存为eslint格式

    vscode个人设置 // vscode的个人设置配置 { "workbench.iconTheme": "vscode-icons", "workb ...

  3. [转]WinForm下Splash(启动画面)制作

    本文转自:http://www.smartgz.com/blog/Article/1088.asp 原文如下: 本代码可以依据主程序加载进度来显示Splash. static class Progra ...

  4. python--json和pickle序列化

    字符串存储 一般需要有信息需要记录的都写到文件上面,把要记录的信息转成字符串,然后在写入到文件中.这算是一种记录方式. 比如有一组用户信息需要存起来.数据定义好之后就可以写文件. info = { ' ...

  5. Struts2_HelloWorld_6

    为 eclipse 在编写 xml配置文件时提供提示,需要加上dtd或xls的标签定义文件的路径,具体操作: 1.Window——Preferences——XML Catalog 2.添加 dtd 文 ...

  6. Yii2.0 安装yii2-queue并在Linux启动守护进程监听消息

    一.什么是yii2-queue? Yii2-queue是Yii2.0 PHP框架下一个消息队列拓展插件,支持基于DB, Redis, RabbitMQ, AMQP, Beanstalk 和 Gearm ...

  7. 分布式爬虫-Kafka监控

    分布式爬虫-Kafka监控 1.介绍

  8. 国外统计学课程主页Statistical Books, Manuals and Journals

    国外统计学课程主页Statistical Books, Manuals and Journalshttp://statpages.info/javasta3.html

  9. 单调队列 poj2823,fzu1894

    题目链接:http://poj.org/problem?id=2823 用RMQ超时了,我想应该是不会的,看discuss说,之前RMQ过了. 维护两个单调队列. 单调递减的队列,每插入一个时: 超过 ...

  10. centos 开启http代理tinyproxy

    一.前言 就算有一些公司想到要进行压力测试也是用一些微软,官网出的一些软件,一个ip发起很多访问.等有一天黑客攻击来了发现还是顶不住.华盟君认为知此知彼才是压力测试的关键点,应当模拟黑客手法进行压力测 ...