Codeforces Round #430 (Div. 2) D. Vitya and Strange Lesson
因为抑或,一眼字典树
但是处理起来比较难
#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的更多相关文章
- Codeforces Round #430 (Div. 2) Vitya and Strange Lesson
D.Vitya and Strange Lesson(字典树) 题意: 给一个长度为\(n\)的非负整数序列,\(m\)次操作,每次先全局异或\(x\),再查询\(mex\) \(1<=n< ...
- 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.直接暴力判断即 ...
- 【Codeforces Round #430 (Div. 2) A C D三个题】
·不论难度,A,C,D自己都有收获! [A. Kirill And The Game] ·全是英文题,述大意: 给出两组区间端点:l,r,x,y和一个k.(都是正整数,保证区间不为空),询问是否 ...
- D. Vitya and Strange Lesson Codeforces Round #430 (Div. 2)
http://codeforces.com/contest/842/problem/D 树 二进制(路径,每个节点代表一位) #include <cstdio> #include < ...
- 【Codeforces Round #430 (Div. 2) D】Vitya and Strange Lesson
[链接]点击打开链接 [题意] 给出一个数组,每次操作将整个数组亦或一个数x,问得到的数组的结果中的mex.mex表示为自然数中第一个没有出现过的数. [题解] 异或的效果是可以累加的,所以不用每次都 ...
- 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 ...
- C - Ilya And The Tree Codeforces Round #430 (Div. 2)
http://codeforces.com/contest/842/problem/C 树 dp 一个数的质因数有限,用set存储,去重 #include <cstdio> #includ ...
- 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 ...
- Codeforces Round #430 (Div. 2) - D
题目链接:http://codeforces.com/contest/842/problem/D 题意:定义Mex为一个序列中最小的未出现的正整数,给定一个长度为n的序列,然后有m个询问,每个询问给定 ...
随机推荐
- Java程序占用的内存可能会大于Xmx
很多人认为Xmx和-Xms参数指定的就是Java程序将会占用的内存,但是这实际上只是Java堆对象将会占用的内存.堆只是影响Java程序占用内存数量的一个因素. 除了堆,影响Java程序所占用内存的因 ...
- hdu 5730 Shell Necklace [分治fft | 多项式求逆]
hdu 5730 Shell Necklace 题意:求递推式\(f_n = \sum_{i=1}^n a_i f_{n-i}\),模313 多么优秀的模板题 可以用分治fft,也可以多项式求逆 分治 ...
- hdu 4609 3-idiots [fft 生成函数 计数]
hdu 4609 3-idiots 题意: 给出\(A_i\),问随机选择一个三元子集,选择的数字构成三角形的三边长的概率. 一开始一直想直接做.... 先生成函数求选两个的方案(注意要减去两次选择同 ...
- 使用xUnit为.net core程序进行单元测试(4)
第1部分: http://www.cnblogs.com/cgzl/p/8283610.html 第2部分: http://www.cnblogs.com/cgzl/p/8287588.html 第3 ...
- 在Windows下为PHP5.5安装redis扩展
使用phpinfo()函数查看PHP的版本信息,这会决定扩展文件版本 根据PHP版本号,编译器版本号和CPU架构, 选择php_redis-2.2.5-5.5-ts-vc11-x86.zip和ph ...
- 解决react-router4在browserhistory路由下的nginx的白屏或者404问题
使用react-router,官方推荐用browserhistory,美观简洁.但是nginx服务器端的配置也让人头疼. 首先看官方举例的方法: server { location / { try_f ...
- bzoj1150 [CTSC2007]数据备份Backup 双向链表+堆
[CTSC2007]数据备份Backup Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2727 Solved: 1099[Submit][Stat ...
- 树莓派系列教程:1.环境与系统,无显示器无键盘无网线联网并使用PuTTy与VNC图形界面远程登录
本文所需物品清单: Raspberry Pi 3 Model B 主板.SD卡与读卡器(用于烧录系统) 资料整理来源在文尾 需要下载的资源与工具: 推荐系统-Raspbian 树莓派官方深度定制的硬件 ...
- 机器学习之支持向量机(四):支持向量机的Python语言实现
注:关于支持向量机系列文章是借鉴大神的神作,加以自己的理解写成的:若对原作者有损请告知,我会及时处理.转载请标明来源. 序: 我在支持向量机系列中主要讲支持向量机的公式推导,第一部分讲到推出拉格朗日对 ...
- Sublime Text编辑远程Linux服务器上的文件
sublime有个叫sftp的插件,可以通过它直接打开远程机器上的文件进行编辑,并在保存后直接同步到远程linux服务器上. 用Package Control安装插件 按下Ctrl+Shift+P调出 ...