题目链接:http://codeforces.com/contest/842/problem/D

题解:像这种求一段异或什么的都可以考虑用字典树而且mex显然可以利用贪心+01字典树,和线段树差不多就是比较节点总数和有的数字数比较有限向左边转移。

然后这个异或其实可以利用一个数num与一个一个的x异或然后求异或的mex也是容易的只要判断当前二进制位是1那么左右节点拥有的数字数互换(不用真的互换

只要用转移体现出来就行了)。这里的01字典树写法是类似线段树且利用递归的方法。

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int M = 2e5 + ;
int ch[ * M][] , nodes[ * M];
int node_size , num;
void build(int pos , int node) {
if(pos < ) return;
for(int i = ; i < ; i++) {
ch[node][i] = ++node_size;
nodes[node_size] = ;
build(pos - , ch[node][i]);
}
}
void init() {
node_size = ;
nodes[] = ;
build( , );
}
void Insert(int node , int x , int pos) {
if(pos < ) {
nodes[node] = ;
return ;
}
int id = (x >> pos) & ;
Insert(ch[node][id] , x , pos - );
nodes[node] = nodes[ch[node][id]] + nodes[ch[node][id ^ ]];
}
int query(int node , int x , int pos) {
if(pos < ) return x;
int gg = (num >> pos) & ;
if(nodes[ch[node][gg]] < ( << pos)) return query(ch[node][gg] , x , pos - );
return query(ch[node][gg ^ ] , x | ( << pos) , pos - );
}
int main() {
int n , m , x;
num = ;
init();
scanf("%d%d" , &n , &m);
for(int i = ; i < n ; i++) {
scanf("%d" , &x);
Insert( , x , );
}
for(int i = ; i < m ; i++) {
scanf("%d" , &x);
num ^= x;
printf("%d\n" , query( , , ));
}
return ;
}

最新文章

  1. Android Studio 解决更新慢的问题
  2. winform实现word转换为PDF(.doc)
  3. 16款最佳HTML5超酷动画演示及源码
  4. android开发 更新升级安装到一半自动闪退
  5. makefile 中 $@ $^ %&lt; 使用
  6. javascript之事件
  7. java设计原则:16种原则
  8. win10 uwp 打开文件管理器选择文件
  9. java对象引用-要掌握的细节
  10. hive:框架理解
  11. JavaScript替换HTML标签
  12. 云计算openstack共享组件(1)——时间同步服务ntp
  13. react 在IE9下input标签使用e.target.value取值失败
  14. 爬虫3 requests基础之下载图片用content(二进制内容)
  15. idea搭spring boot项目
  16. 使用pwm进行呼吸灯的设计
  17. JavaScript中遍历数组和对象的方法
  18. omnigraffle 的一些总结
  19. ArcGIS Pro 获得工具的个数
  20. jenkins构建多个项目执行顺序设置

热门文章

  1. Could not load NIB in bundle: &#39;NSBundle.....
  2. maven私服nexus上传第三方jar包以及下载
  3. UE4中UMG与C++交互 页面文本修改
  4. Mac环境下升级gcc版本--rocksdb
  5. python虚拟环境完美部署
  6. C#开发可播放摄像头及任意格式视频的播放器
  7. 武林 HDU - 1107
  8. Dubbo的基本介绍及使用
  9. 配置Oracle透明网关用以连接 SQLServer经验总结
  10. Java网络编程 -- BIO 阻塞式网络编程