因为抑或,一眼字典树
但是处理起来比较难

#include<iostream>
#include<map>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 6e6+5;
#define MS(x,y) memset(x,y,sizeof(x))
#define MP(x, y) make_pair(x, y)
const int INF = 0x3f3f3f3f; int nx[N][2];
int cnt[N];
int has[N];
int tot;
void insert(int x) {
int rt = 0;
for(int i = 18; i >= 0; --i) {
int tt = (x>>i) & 1;
// printf("%d\n", rt);
if(!nx[rt][tt]) {
nx[rt][tt] = ++tot;
}
rt = nx[rt][tt];
cnt[rt] ++;
}
// has[rt] = 1;
}
void search(int x) {
int rt = 0;
int ans = 0;
for(int i = 18; i >= 0; --i) {
int tt = (x >> i) & 1;
if( (1<<i) - cnt[nx[rt][0 ^ tt]] ) {
if(cnt[nx[rt][0 ^ tt]] == 0) break;
rt = nx[rt][0 ^ tt];
}else {
if(cnt[nx[rt][1 ^ tt]] == 0) {
// printf("hh\n");
ans += 1<<i;
break;
} rt = nx[rt][1 ^ tt]; ans += 1<<i;
}
// printf("%d %d\n", rt, 0^tt);
}
printf("%d\n", ans);
}
int main() {
int n, m;
while(~scanf("%d %d", &n, &m)) {
MS(nx, 0);
MS(cnt, 0);
tot = 0;
map<int, int> mp;
for(int i = 1; i <= n; ++i) {
int a; scanf("%d", &a);
if(mp.find(a) == mp.end()) insert(a);
mp[a] ++;
}
int tmp = 0;
for(int i = 0; i < m; ++i) {
int a; scanf("%d", &a);
tmp ^= a;
search(tmp);
}
}
return 0;
}

Codeforces Round #430 (Div. 2) D. Vitya and Strange Lesson的更多相关文章

  1. Codeforces Round #430 (Div. 2) Vitya and Strange Lesson

    D.Vitya and Strange Lesson(字典树) 题意: 给一个长度为\(n\)的非负整数序列,\(m\)次操作,每次先全局异或\(x\),再查询\(mex\) \(1<=n< ...

  2. Codeforces Round #430 (Div. 2) 【A、B、C、D题】

    [感谢牛老板对D题的指点OTZ] codeforces 842 A. Kirill And The Game[暴力] 给定a的范围[l,r],b的范围[x,y],问是否存在a/b等于k.直接暴力判断即 ...

  3. 【Codeforces Round #430 (Div. 2) A C D三个题】

    ·不论难度,A,C,D自己都有收获! [A. Kirill And The Game] ·全是英文题,述大意:    给出两组区间端点:l,r,x,y和一个k.(都是正整数,保证区间不为空),询问是否 ...

  4. D. Vitya and Strange Lesson Codeforces Round #430 (Div. 2)

    http://codeforces.com/contest/842/problem/D 树 二进制(路径,每个节点代表一位) #include <cstdio> #include < ...

  5. 【Codeforces Round #430 (Div. 2) D】Vitya and Strange Lesson

    [链接]点击打开链接 [题意] 给出一个数组,每次操作将整个数组亦或一个数x,问得到的数组的结果中的mex.mex表示为自然数中第一个没有出现过的数. [题解] 异或的效果是可以累加的,所以不用每次都 ...

  6. Codeforces Round #373 (Div. 2) A. Vitya in the Countryside 水题

    A. Vitya in the Countryside 题目连接: http://codeforces.com/contest/719/problem/A Description Every summ ...

  7. C - Ilya And The Tree Codeforces Round #430 (Div. 2)

    http://codeforces.com/contest/842/problem/C 树 dp 一个数的质因数有限,用set存储,去重 #include <cstdio> #includ ...

  8. Codeforces Round #430 (Div. 2) C. Ilya And The Tree

    地址:http://codeforces.com/contest/842/problem/C 题目: C. Ilya And The Tree time limit per test 2 second ...

  9. Codeforces Round #430 (Div. 2) - D

    题目链接:http://codeforces.com/contest/842/problem/D 题意:定义Mex为一个序列中最小的未出现的正整数,给定一个长度为n的序列,然后有m个询问,每个询问给定 ...

随机推荐

  1. 序列化与transient

    满足下面四个条件中的一个的类就不应该被序列化:  1.一个类与本地代码(native code)有紧密的关系,如java.util.zip.Deflater,这个类中很多都是native的. 2.对象 ...

  2. 2018/1/8 学习汇总,kettle简单介绍,集合遍历方式的选择及原理,防止表单重复提交的后台解决方案

    昨天因为当前这个二次开发项目的接近尾声,要求我们将生产环境数据库里的数据迁移到现在新的数据库来,但老数据库里是sqlserver而新数据库则是ORACLE,不仅仅面对着数据库数据类型结构不一致的问题, ...

  3. Spring bean的生命周期详解

    bean的生命周期1.实例化bean 即new2.按照spring上下文对实例化的bean进行配置 即填充属性,也就是IOC/DI(控制反转,依赖注入)3.如果这个bean实现了BeanNameAwa ...

  4. Sublime3中如何安装markdown插件支持

    参考文章 Sublime Text下使用markdown的环境搭建和配置 MarkDown生成目录索引 按下键Ctrl+Shift+p调出命令面板,找到Package Control: install ...

  5. FastStone Capture的使用

    FastStone Capture的使用 FastStone Capture是一款精简而优秀的图像处理软件,在工作中会经常用到.我在本地安装了FastStone Capture 8.4版本 (提取码: ...

  6. Go解析写死的json

    func TestAliAfpAdapter_AskAd_Banner(t *testing.T) { apiData := getApiData() apiData.ApiInfo.ApiPosit ...

  7. pyDash:一个基于 web 的 Linux 性能监测工具

    pyDash 是一个轻量且基于 web 的 Linux 性能监测工具,它是用 Python 和 Django 加上 Chart.js 来写的.经测试,在下面这些主流 Linux 发行版上可运行:Cen ...

  8. Ehcache入门基础

    1.ehcache的简介  EhCache 是一个纯Java的进程内缓存框架,具有快速.精干等特点,是Hibernate中默认的CacheProvider. 2.ehcache入门实例 1.首先先导入 ...

  9. MysqL_SELECT FOR UPDATE详解

    先来举一个在某些应用场景下会出现数据不一致的例子,当然存储引擎是InnoDB(至于为什么,后面再告诉你). 电商平台常见的下单场景: 一般商品表(goods)有基本的四个字段,id(主键),goods ...

  10. Ecshop中transport和jquery不兼容的解决方案

    1.修改文件:/js/transport.js,在最底部增加代码 if (Object.prototype.toJSONString){ var oldToJSONString = Object.to ...