当前位置:网站首页>给定一个数在序列中求最大异或值(01字典)
给定一个数在序列中求最大异或值(01字典)
2022-06-29 17:47: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));
}
}边栏推荐
- Two controller layer interface authentication methods
- 底层内功修养
- 基于STM32F103ZET6库函数独立看门狗(IWDG)实验
- [try to hack] cookies and sessions
- Maidong Internet won the bid of Dajia Insurance Group
- 金鱼哥RHCA回忆录:DO447构建高级作业工作流--使用事实缓存提高性能
- VB. Net read / write NFC ntag tag source code
- Epoll analysis
- How MySQL queries character set codes of tables
- Visio annotation, annotation location
猜你喜欢

育润多维发力慈善领域,勇抗企业公益大旗

【WebDriver】使用AutoIt上传文件

What are the usage scenarios for locks in MySQL

力扣每日一题 06.29 两数相加

Inherit Chinese virtues, pay attention to the health of the middle-aged and the elderly, and Yurun milk powder has strong respect for the elderly

Two controller layer interface authentication methods

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

OpenFeign使用步骤 轮询策略与权重 log4j使用 openFeign拦截器的配置

Openfeign use step polling strategy and weight log4j configuration of openfeign interceptor

How MySQL queries character set codes of tables
随机推荐
reflex
Opencv+yolo-v3 for target tracking
L'intercepteur handlerinterceptor personnalisé permet l'authentification de l'utilisateur
基于STM32F103ZET6库函数定时器中断实验
力扣每日一题 06.29 两数相加
传承中华美德,关注中老年大健康,育润奶粉敬老情浓
VB.Net读写NFC Ntag标签源码
Distributed | several steps of rapid read / write separation
人脸识别4-百度商用方案调研
Force deduction daily question 06.29 add two numbers
MaxCompute字符串替换函数-replace
[try to hack] cookies and sessions
[Oracle] basic knowledge interview questions
软件快速交付真的需要以安全为代价吗?
Matlab farthest point sampling (FPS)
3h精通OpenCV(七)-颜色检测
Partial mock of static class of phpunit operation
小程序容器是什么技术?能助力物联网企业红海突围?
Visual Studio插件CodeRush正式发布v22.1——优化调试可视化工具
基于STM32F103ZET6库函数独立看门狗(IWDG)实验