当前位置:网站首页>Find the maximum XOR value in the sequence given a number (01 Dictionary)
Find the maximum XOR value in the sequence given a number (01 Dictionary)
2022-06-29 17:56:00 【eva_ can(not)survive】
int s[MAXN];
int tri[MAXN][2],cnt;
int num[MAXN];
void init(){
memset(tri,0,sizeof(tri));
memset(num,0,sizeof(num));
cnt=1;
}
void insert(int n){
int cur=1;
for(int i=MAXBIT;i>=0;i--){
int bit=n>>i&1;
if(!tri[cur][bit]) tri[cur][bit]=++cnt;
cur=tri[cur][bit];
}
num[cur]=n;
}
int find_max(int x){
int cur=1;
for(int i=MAXBIT;i>=0;i--){
int bit=x>>i&1;
if(tri[cur][bit^1]) cur=tri[cur][bit^1];
else cur=tri[cur][bit];
}
return num[cur];
}
void _solve(){
init();
int n,m;
scanf("%d %d",&n,&m);
for(int i=1;i<=n;i++){
scanf("%d",s+i);
insert(s[i]);
}
ll k;
for(int i=1;i<=m;i++){
scanf("%d",&k);
printf("%d\n",find_max(k));
}
}边栏推荐
猜你喜欢

Distributed | several steps of rapid read / write separation

剖析下零拷贝机制的实现原理,适用场景和代码实现

两种Controller层接口鉴权方式

Yurun multidimensional makes efforts in the charity field and bravely resists the corporate public welfare banner
![Fill in the next right node pointer of each node [make good use of each point - > reduce the space-time complexity as much as possible]](/img/33/bda0a898bfe3503197026d1f62e851.png)
Fill in the next right node pointer of each node [make good use of each point - > reduce the space-time complexity as much as possible]

selenium上传文件

js两个二维数组合并并去除相同项(整理)
![Split palindrome string [dp + DFS combination]](/img/7b/221b000984977508f849e19802c2c2.png)
Split palindrome string [dp + DFS combination]

How to create and delete MySQL triggers

小白月赛51 补题 E G F
随机推荐
/usr/bin/ld: warning: **libmysqlclient.so.20**, needed by //usr/
小程序容器是什么技术?能助力物联网企业红海突围?
剖析下零拷贝机制的实现原理,适用场景和代码实现
mac安装php7.2
Prevent form resubmission based on annotations and interceptors
Createstore for Redux source code analysis
Partial mock of static class of phpunit operation
关于日期相加减问题
传承中华美德,关注中老年大健康,育润奶粉敬老情浓
一次采集JSON解析错误的修复
selenium 组合键操作
Analyze the implementation principle of zero copy mechanism, applicable scenarios and code implementation
2022 spring summer collection koreano essential reshapes the vitality of fashion
Distributed | several steps of rapid read / write separation
Opencv+YOLO-V3实现目标跟踪
测试dble split功能执行+导入耗时shell脚本参考
SCM系统是什么?供应链管理系统有哪些优势?
What is the SRM system? How do I apply the SRM system?
lodash深拷贝使用
小迈科技 X Hologres:高可用的百亿级广告实时数仓建设