#include <iostream>
#include <cstdio>
using namespace std;
int s[2000005][2], cnt, n, m, x, uu, ans, dep[2000005], siz[2000005];
void ins(){
int u=0;
for(int i=19; i>=0; i--){
int t=(x&(1<<i))>0;
if(!s[u][t]) s[u][t] = ++cnt;
u = s[u][t];
}
}
void dfs(int o){
if(o) siz[o] = 1;
if(s[o][0]) dfs(s[o][0]);
if(s[o][1]) dfs(s[o][1]);
siz[o] += siz[s[o][0]] + siz[s[o][1]];
}
void getAns(){
int u=0;
for(int i=19; i>=0; i--){
int t=(x&(1<<i))>0;
if(siz[s[u][t]]!=(1<<(i+1))-1){
ans |= t<<i;
u = s[u][t];
}
else{
ans |= (t^1)<<i;
u = s[u][t^1];
}
}
}
int main(){
cin>>n>>m;
for(int i=1; i<=n; i++){
scanf("%d", &x);
ins();
}
x = 0;
dfs(0);
while(m--){
ans = 0;
scanf("%d", &uu);
x ^= uu;
getAns();
printf("%d\n", ans^x);
}
return 0;
}

cf842d Vitya and Strange Lesson的更多相关文章

  1. 【cf842D】Vitya and Strange Lesson(01字典树)

    D. Vitya and Strange Lesson 题意 数列里有n个数,m次操作,每次给x,让n个数都异或上x.并输出数列的mex值. 题解 01字典树保存每个节点下面有几个数,然后当前总异或的 ...

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

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

  3. Codeforces Round #430 D. Vitya and Strange Lesson

    Today at the lesson Vitya learned a very interesting function - mex. Mex of a sequence of numbers is ...

  4. Vitya and Strange Lesson CodeForces - 842D 字典树+交换节点

    题意: Today at the lesson Vitya learned a very interesting function - mex. Mex of a sequence of number ...

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

    因为抑或,一眼字典树 但是处理起来比较难 #include<iostream> #include<map> #include<iostream> #include& ...

  6. codeforces 842D Vitya and Strange Lesson

    题目大意: 定义mex数为数组中第一个没有出现的非负整数.有m个操作,每个操作有一个x,将数组中所有的元素都异或x,然后询问当前的mex Input First line contains two i ...

  7. Codeforces.842D.Vitya and Strange Lesson(Trie xor)

    题目链接 /* 异或只有两种情况,可以将序列放到01Tire树上做 在不异或的情况下在Tire上查找序列的mex很容易,从高位到低位 如果0位置上数没有满,则向0递归:否则向1 (0位置上的数都满了 ...

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

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

  9. D. Vitya and Strange Lesson

    http://codeforces.com/contest/842/problem/D 1.整体的数组是不用变的,比如数组a[]经过一次询问x后,然后再询问y,相当于询问x ^ y ^ a[i]后的m ...

随机推荐

  1. [已读]HTML5与CSS3设计模式

    我想说,不要被书名骗了,其实并没有涉及丁点h5与css3的内容,但是确实称得上比较详细的一本关于css的书.看它的页数就知道了,481~~ 今年上半年看完的,现在想想,觉得自己还是蛮拼的.内容会比较枯 ...

  2. Super Mario 树状数组离线 || 线段树

    Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  3. (译文)IOS block编程指南 4 声明和创建blocks

    Declaring and Creating Blocks (声明和创建blocks) Declaring a Block Reference (声明一个block引用) Block variable ...

  4. (译文)IOS block编程指南 3 概念总览

    Conceptual Overview(概览) Block objects provide a way for you to create an ad hoc function body as an ...

  5. (转)Spring的概述

    http://blog.csdn.net/yerenyuan_pku/article/details/69663685 Spring的概述 什么是Spring 据度娘所载: Spring是一个开源框架 ...

  6. uva1627 Team them up!

    注意这题要求互相认识不认识的人之间连一条线一个人在组1,那么不认识(互相认识)的人就在组0:同时这些人不认识的人就在组1.每个联通分量都可以独立推导,遇到矛盾则无解一个联通分量有一个核心,其他的点是分 ...

  7. Linux-RedHat7.2 安装.net core2.0

    1.添加dotnet产品Feed sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc sudo sh -c 'ech ...

  8. vue props 下有验证器 validator 验证数据返回true false后,false给default值

    vue props 下有验证器 validator 验证数据返回true false后,false给default值 props: { type: { validator (value) { retu ...

  9. js 时间戳 随机数 new Date().getTime()

    一:时间转时间戳:javascript获得时间戳的方法有四种,都是通过实例化时间对象 new Date() 来进一步获取当前的时间戳 1.var timestamp1 = Date.parse(new ...

  10. 一个Lucene.Net的Demo

    今天突然想来看一下全文检索,于是就了解了一下Lucene.Net,然后把公司目前的产品表拿来练手,写了这么个Demo. 先看一下Demo的代码 public class ProductReposito ...