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个询问,每个询问给定 ...
随机推荐
- Python基础篇(七)
加上两个下划线变量或者方法变为私有. >>> class Bird: ... __song = "spark" ... def sing(self): ...
- 洛谷 [P1220] 关路灯
本题是一道区间DP,很容易设计出状态, dp[i][j]代表关掉i到j的路灯所耗的电量,但是对于新到一个路灯来说,可以是原来直接来的,也可以是掉头来的,于是还需要添加一维 0代表在区间的左端,1代表在 ...
- bzoj 3033: 太鼓达人 [欧拉回路]
3033: 太鼓达人 题意:长m的01环,每个长k的子串都是不同的01串.给出k,求最大的M以及字典序最小的方案. \(M=2^k\) 可以把k-1位01串看成点,k位01串就是边,满足欧拉回路的条件 ...
- [实例]JAVA调用微信接口发送图文消息,不用跳到详情页
package com.test; import java.io.IOException; import java.io.InputStream; import java.io.OutputStrea ...
- js短路表达式
今天碰见个题目,感觉短路表达式很好用. 题目: 定义一个计算圆面积的函数area_of_circle(),它有两个参数: r: 表示圆的半径: pi: 表示π的值,如果不传,则默认3.14 funct ...
- 我的前端故事----来聊聊怎么写react-native上的样式吧
我遇到了什么问题? 不久之前我重构了一个古老的项目,总结了一些js方面的想法,不过对于一个前端项目而言不仅仅只由js组成的嘛,上学的时候老师和我说HTML+CSS+JS对应的是页面的骨架.皮肤和肌肉. ...
- php 压缩函数gzencode gzdeflate gzcompress
gzencode 默认使用ZLIB_ENCODING_GZIP编码,使用gzip压缩格式,实际上是使用defalte 算法压缩数据,然后加上文件头和adler32校验 gzdeflate 默认使用ZL ...
- 网络配置:linux学习第一篇
1. 先使用dhclient获取ip 再使用命令ip addr查看获取到的ip 2. 设置静态IP 编辑网卡配置文件,路径: 3. 重启网络服务 命令:systemctl ...
- Windows 桌面和文件夹的右键->打开命令行窗口
Windows 桌面和文件夹的右键->打开命令行窗口 1.先按下shift,再点鼠标右键运行CMD,(不是管理员权限) 上图是我已经加了右键的,并且 系统设置了 ps代替cmd,所以是“在此处 ...
- C/C++语言简介之发展历史
C语言之所以命名为C,是因为 C语言源自Ken Thompson发明的B语言,而 B语言则源自BCPL语言. 1967年,剑桥大学的Martin Richards对CPL语言进行了简化,于是产生了BC ...