cf842d Vitya and Strange Lesson
#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的更多相关文章
- 【cf842D】Vitya and Strange Lesson(01字典树)
D. Vitya and Strange Lesson 题意 数列里有n个数,m次操作,每次给x,让n个数都异或上x.并输出数列的mex值. 题解 01字典树保存每个节点下面有几个数,然后当前总异或的 ...
- Codeforces Round #430 (Div. 2) Vitya and Strange Lesson
D.Vitya and Strange Lesson(字典树) 题意: 给一个长度为\(n\)的非负整数序列,\(m\)次操作,每次先全局异或\(x\),再查询\(mex\) \(1<=n< ...
- 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 ...
- Vitya and Strange Lesson CodeForces - 842D 字典树+交换节点
题意: Today at the lesson Vitya learned a very interesting function - mex. Mex of a sequence of number ...
- Codeforces Round #430 (Div. 2) D. Vitya and Strange Lesson
因为抑或,一眼字典树 但是处理起来比较难 #include<iostream> #include<map> #include<iostream> #include& ...
- codeforces 842D Vitya and Strange Lesson
题目大意: 定义mex数为数组中第一个没有出现的非负整数.有m个操作,每个操作有一个x,将数组中所有的元素都异或x,然后询问当前的mex Input First line contains two i ...
- Codeforces.842D.Vitya and Strange Lesson(Trie xor)
题目链接 /* 异或只有两种情况,可以将序列放到01Tire树上做 在不异或的情况下在Tire上查找序列的mex很容易,从高位到低位 如果0位置上数没有满,则向0递归:否则向1 (0位置上的数都满了 ...
- D. Vitya and Strange Lesson Codeforces Round #430 (Div. 2)
http://codeforces.com/contest/842/problem/D 树 二进制(路径,每个节点代表一位) #include <cstdio> #include < ...
- D. Vitya and Strange Lesson
http://codeforces.com/contest/842/problem/D 1.整体的数组是不用变的,比如数组a[]经过一次询问x后,然后再询问y,相当于询问x ^ y ^ a[i]后的m ...
随机推荐
- 17972 Golden gun的巧克力
17972 Golden gun的巧克力 时间限制:1000MS 内存限制:65535K提交次数:93 通过次数:13 收入:124 题型: 编程题 语言: G++;GCC;JAVA Descr ...
- AJPFX循环结构整理资料
Java语言基础(循环结构概述和for语句的格式及其使用)* A:循环结构的分类 * for,while,do...while * B:循环结构for语句的格式:* ...
- dubbo系列--重要概念介绍
dubbo架构图 节点角色说明 整体设计 proxyFactory:就是为了获取一个接口的代理类,例如获取一个远程接口的代理.它有2个方法,代表2个作用 getInvoker:针对server端,将服 ...
- Spring数据访问1 - 数据源配置及数据库连接池的概念
无论你要选择哪种数据访问方式,首先你都需要配置好数据源引用. Spring中配置数据源的几种方式 通过在JDBC驱动程序定义的数据源: 通过JNDI查找的数据源: 连接池的数据源: 对于即将发布到生产 ...
- hihocoder1736 最大的K-偏差排列
思路: 容易写错的贪心题. 实现: #include <bits/stdc++.h> using namespace std; int main() { int n, k; while ( ...
- 最新精品 强势来袭 XP,32/64位Win7,32/64位Win8,32/64位Win10系统【国庆版版】
本系统是10月最新完整版本的Windows10 安装版镜像,Win10正式版,更新了重要补丁,提升应用加载速度,微软和百度今天宣布达成合作,百度成为Win10 Edge浏览器中国默认主页和搜索引擎,系 ...
- android开发中设置字体
转自:http://segmentfault.com/q/1010000000494116 http://ryanhoo.github.io/blog/2014/05/05/android-bette ...
- exit - 使程序正常中止
SYNOPSIS 总览 #include <stdlib.h> void exit(int status); DESCRIPTION 描述 函数 exit() 使得程序正常中止,statu ...
- selelinum+PhantomJS 爬取拉钩网职位
使用selenium+PhantomJS爬取拉钩网职位信息,保存在csv文件至本地磁盘 拉钩网的职位页面,点击下一页,职位信息加载,但是浏览器的url的不变,说明数据不是发送get请求得到的. 我们不 ...
- 如何改android device monitor文件的权限
adb.exe在c/Android/platform-tools目录下,在这个目录下打开终端,然后adb shell,然后su http://blog.csdn.net/u012719153/arti ...