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

Input

First line contains two integer numbers n and m (1 ≤ n, m ≤ 3·105) — number of elements in array and number of queries.

Next line contains n integer numbers ai (0 ≤ ai ≤ 3·105) — elements of then array.

Each of next m lines contains query — one integer number x (0 ≤ x ≤ 3·105).

Output

For each query print the answer on a separate line.

Examples
Input
2 2
1 3
1
3
Output
1
0
Input
4 3
0 1 5 6
1
2
4
Output
2
0
0
Input
5 4
0 1 5 6 7
1
1
4
5
Output
2
2
0
2
2
0
0
Input
5 4
0 1 5 6 7
1
1
4
5
Output
2
2
0
2
%%%%yzh大佬,学会了新姿势:http://www.cnblogs.com/Yuzao/default.html?page=1这题正解其实是01Trie
按照理解,Trie用来保存字符串,但也可以通过01分支来保存数
这样我们只要找到树中最靠左的空节点,对应的值即为答案
更新可以用lazy标记,如果有标记,则反转左右子节点
如果左边有空节点,那么就返回向左查找的值
没有则返回右节点查找的值+2^(dep-1)[左节点数量]
然后注意本题是按高位向低位拓展,因为高位分支少,所以会更快

YZD&&HJW&&SAC&&YZH%%%orz大佬
 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
struct Node
{
int l,r;
}c[];
int seg[],rev[],root,tot,n,m;
void insert(int &rt,int x,int dep)
{
if (!rt) rt=++tot;
if (dep==)
{
seg[rt]=;
return;
}
if (x&(<<dep-)) insert(c[rt].r,x,dep-);
else insert(c[rt].l,x,dep-);
seg[rt]=seg[c[rt].l]&&seg[c[rt].r];
}
void pushdown(int &rt,int dep)
{
if (rev[rt]==) return;
int k=rev[rt];
rev[c[rt].l]^=k;
rev[c[rt].r]^=k;
if (k&(<<dep-))
swap(c[rt].l,c[rt].r);
rev[rt]=;
}
int query(int &rt,int dep)
{
if (dep==) return ;
pushdown(rt,dep);
if (seg[c[rt].l]==) return query(c[rt].l,dep-);
else return query(c[rt].r,dep-)+(<<dep-);
}
int main()
{int i,j,x;
cin>>n>>m;
for (i=;i<=n;i++)
{
scanf("%d",&x);
insert(root,x,);
}
for (i=;i<=m;i++)
{
scanf("%d",&x);
rev[root]^=x;
printf("%d\n",query(root,));
}
}

codeforces 842D Vitya and Strange Lesson的更多相关文章

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

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

  2. CodeForeces 842d Vitya and Strange Lesson ——(带lazy标记的01字典树)

    给一个序列,每次操作对这个序列中的所有数异或一个x,问每次操作完以后整个序列的mex值. 做法是去重后构建01字典树,异或x就是对root加一个x的lazy标志,每次pushDown时如果lazy的这 ...

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

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

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

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

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

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

  6. 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 ...

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

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

  8. codeforces 842 D. Vitya and Strange Lesson(01字典树+思维+贪心)

    题目链接:http://codeforces.com/contest/842/problem/D 题解:像这种求一段异或什么的都可以考虑用字典树而且mex显然可以利用贪心+01字典树,和线段树差不多就 ...

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

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

随机推荐

  1. 游戏安全有多重要?——GAME-TECH游戏开发者技术沙龙

    欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由云+社区运营团队发布在腾讯云+社区 腾讯云GAME-TECH沙龙继3月深圳站后,将于4月13日来到北京站,与游戏厂商和游戏开发者,畅聊 ...

  2. 记录python接口自动化测试--从excel中读取params参数传入requests请求不生效问题的解决过程(第七目)

    在第六目把主函数写好了,先来运行一下主函数 从截图中可以看到,请求参数打印出来了,和excel中填写的一致 但是每个接口的返回值却都是400,提示参数没有传进去,开始不知道是什么原因(因为excel中 ...

  3. Beta No.1

    一.今日任务 重新熟悉整体项目 对整个项目在未来的beta冲刺中进程有一个合理的规划 由于我们送出的是一个负责前端的成员,引入的也是一个负责前端工作的女生,(女生做起美工比起男生更加得心应手吧)所以我 ...

  4. js 选择图片生成base64数据

    <!doctype html> <html> <head> <meta charset="utf-8"> <meta http ...

  5. 搭建java环境——使用Sublime Text 3(windows环境)

    实现sublime Text 3对Java编译执行 参考网址:http://tieba.baidu.com/p/2609515186 1.1直接在安装路径下找到*\Packages\Java.subl ...

  6. win10 安装mingw ruby rails

    原文可以参考 https://ruby-china.org/topics/17581 在window10 安装ruby rails https://rubyinstaller.org/download ...

  7. nyoj 移位密码

    移位密码 时间限制:1000 ms  |  内存限制:65535 KB 难度:0   描述 移位密码是最简单的一类代替密码,具体算法就是将字母表的字母右移k个位置(k<26),并对字母表长度作模 ...

  8. Win10下, TortoiseGit安装及配合Gitee使用完整版

    Windows10下, TortoiseGit的安装及使用, 并配合Gitee码云使用! 1) 安装TortoiseGit 官网, 32位, 64位, 自选 https://tortoisegit.o ...

  9. LAMP 搭建

    p { margin-bottom: 0.25cm; line-height: 120% } LAMP 搭建 承 Ubuntu 17.10.1安装, 定制. 参考 电子工业出版社, Ubuntu完美应 ...

  10. 05_Linux目录文件操作命令2_我的Linux之路

    这一节我们继续来学习Linux中对文件和目录的操作命令 mkdir 创建目录 mkdir (选项)(参数) 在Linux端可以使用mkdir来创建目录,如果你没有加其他的路径名,那么默认是在当前目录下 ...