#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. 水题 Codeforces Round #303 (Div. 2) D. Queue

    题目传送门 /* 比C还水... */ #include <cstdio> #include <algorithm> #include <cstring> #inc ...

  2. Altium Designer的一些功能

    一 Snippets:将原理图或PCB的部分模块电路保存以便于以后重用.https://wenku.baidu.com/view/412a0dbcf121dd36a32d8217.html 二 设备制 ...

  3. C#将excel数据按照需求导入Sql server遇到的问题(参考而已)

    1.千万不要使用永中表格(WPS没用过,这里只是个人观点,不是说永中表格的) 我在公司得到的任务是将excel数据按照需求导入数据库总共主表大概3张,所以有点复杂(列子用的简单表,公司东西还是不要放出 ...

  4. laravel oauth2.0 文件上传报错

    报错信息:   "message": "Invalid stream or file provided for UploadedFile",    " ...

  5. Netty实现WebSocket

    package com.qmtt.server; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; ...

  6. AJPFX浅谈Java性能优化之finalize 函数

    ★finalize 函数的调用机制 俺经常啰嗦:“了解本质机制的重要性”.所以今天也得先谈谈 finalize 函数的调用机制.在聊之前,先声明一下:Java虚拟机规范,并没有硬性规定垃圾回收该不该搞 ...

  7. 进程间通信的两种实现方式(IPC)

    进程间通信的两种实现方式(IPC) IPC: iter processing communicate 进程间通信:IPC(iter process communicate)linux free-m 可 ...

  8. BZOJ1132: [POI2008]Tro(叉积 排序)

    题意 世上最良心题目描述qwq 平面上有N个点. 求出所有以这N个点为顶点的三角形的面积和 N<=3000 Sol 直接模拟是$n^3$的. 考虑先枚举一个$i$,那么我们要算的就是$\sum_ ...

  9. UML建模图实战笔记

    一.前言 UML:Unified Modeling Language(统一建模语言),使用UML进行建模的作用有哪些: 可以更好的理解问题 可以及早的发现错误或者被遗漏的点 可以更加方便的进行组员之间 ...

  10. ios MD5大小写加密

    #import "NSString+change.h" #import <CommonCrypto/CommonDigest.h> @implementation NS ...