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

#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. 万类之父——Object

    jdk1.8.0_144 Object类作为Java中的顶级类,位于java.lang包中.所有的类直接或者间接都继承自它.所以Object类中的方法在所有类中都可以直接调用.在深入介绍它的API时, ...

  2. ASP.NET Core 2.0 : 四. _Layout与_ViewStart

    本章我们新建一个项目,并通过这个项目熟悉一下_Layout与_ViewStart. 新建一个项目 首先, 文件->新建一个解决方案 选择.Net Core 的APP下面的ASP.NET Core ...

  3. 浅析Xilinx 三速以太网MAC IP核

    之前在使用Altera的三速以太网MAC IP的基础上,完成了UDP协议数据传输.此次为了将设计移植到xilinx FPGA上,需要用到xilinx的三速以太网MAC IP核,当然也可以自己用HDL编 ...

  4. shell编程值之正则表达式与字符截取(6)

    正则表达式与通配符 正则表达式用来在文件中匹配符合条件的字符串,正则是包含匹配.grep.awk.sed等命令可以支持正则表达式 通配符用来匹配符合条件的文件名,通配符是完全匹配.ls.find.cp ...

  5. LINUX服务器下用root登录ftp

    因为安全方面的原因,root用户是默认不能登录ftp服务的. 如果一定要用root登录,则: 1.删除或注释/etc/vsftpd.ftpusers中的root 2.删除或注释/etc/vsftpd. ...

  6. 【实用】需要收藏备用的JQuery代码片段

    1 元素屏幕居中 jQuery.fn.center = function () { this.css("position","absolute"); this. ...

  7. 奥酷HTML5视频直播系统AMS6.0

    今日,北极星通自主研发的流媒体服务系统Aoku Media Server6.0发布了,将正式支持HTML5直播,这使得网页中无需有flash播放插件或者其他插件,可直接观看直播,HTML5直播也会使得 ...

  8. 拥抱.NET Core系列:MemoryCache 初识

    Cache是一个绝大多数项目会用到的一个技术,说起到缓存可能就联想到 Set.Add.Get.Remove.Clear 这几个方法.那么在.NET Core中微软给我们带来了什么样的缓存体验呢?今天我 ...

  9. 图书管理系统【JavaWeb:部署开发环境、解决分类、图书、前台页面模块】

    前言 巩固Servlet+JSP开发模式,做一个比较完整的小项目. 成果图 该项目包含了两个部分,前台和后台. 前台用于显示 后台用于管理 该项目可分为5个模块来组成:分类模块,用户模块,图书模块,购 ...

  10. HBuilder常用快捷键

    切换tab: Ctrl+Tab全部保存: Ctrl+Shift+S 激活代码助手: Alt+/显示方法参数提示: Alt+Shift+?转到定义: Ctrl+Alt+D 开启关闭注释整行: Ctrl+ ...