当前位置:网站首页>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));
}
}边栏推荐
- 小程序容器是什么技术?能助力物联网企业红海突围?
- 第42期:MySQL 是否有必要多列分区
- Selenium upload file
- SRM supplier collaborative management system function introduction
- 布隆过滤器:
- mysql. What is the concept of sock
- 两种Controller层接口鉴权方式
- Have you grasped the most frequently asked question in the interview about massive data processing?
- What is the function of MySQL cursors
- Wechat applet development reserve knowledge
猜你喜欢

NVIDIA installs the latest graphics card driver

Let's start with a bug that was cheated by the app store

Face recognition 4- research on Baidu commercial solutions

js两个二维数组合并并去除相同项(整理)

Maidong Internet won the bid of Dajia Insurance Group

传承中华美德,关注中老年大健康,育润奶粉敬老情浓

VB. Net read / write NFC ntag tag source code

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

小迈科技 X Hologres:高可用的百亿级广告实时数仓建设

第42期:MySQL 是否有必要多列分区
随机推荐
关于日期相加减问题
人脸识别4-百度商用方案调研
软件测试——基础理论知识你都不一定看得懂
VB. Net read / write NFC ntag tag source code
Digital twin energy system, creating a "perspective" in the low-carbon era
Timer interrupt experiment based on stm32f103zet6 library function
3h精通OpenCV(九)-最简单的人脸检测
2022 spring summer collection koreano essential reshapes the vitality of fashion
What technology is an applet container? Can it help Internet of things enterprises break through the red sea?
Industry application of smart city based on GIS 3D visualization
基于STM32F103ZET6库函数定时器中断实验
MaxCompute Studio
[Oracle] basic knowledge interview questions
基于STM32F103ZET6库函数串口实验
How to create a virtual image
Xiaomai technology x hologres: high availability of real-time data warehouse construction of ten billion level advertising
Mongotemplate - distinct use
SRM供应商协同管理系统功能介绍
分布式 | 几步快速拥有读写分离
Uploading files using AutoIT