codeforces 842D. Vitya and Strange Lesson
来源:互联网 发布:不干胶设计软件 编辑:程序博客网 时间:2024/06/08 01:40
http://codeforces.com/contest/842/problem/D
思路:
我把数组中的数扔进字典树里,之后我记录下每个状态出现的次数。随后我们不需要去每次都把数组异或,我们把所有查询的数异或,
#include <bits/stdc++.h>#define maxs 2002020#define mme(i,j) memset(i,j,sizeof(i))#define pb push_back#define ll long long#define lala puts("Lalalala")#define ohMyLove ios::sync_with_stdio(false);cin.tie(NULL);using namespace std;const ll inf = LONG_LONG_MAX;int son[maxs][3],val[maxs];int rt,tot;void init(){ rt=0; tot=1; mme(son[rt],0);}void Insert(int x){ int now=rt,id; for(int i=20; i>=0; i--) { id = ((x>>i)&1); if(!son[now][id]) son[now][id]=tot++; now = son[now][id]; val[now]++; }}int query(int x){ int now=rt,id,ans=0; for(int i=20; i>=0; i--) { id = ( (x>>i) & 1 ); if(!son[now][id]) return ans; if(val[son[now][id]]==(1<<i)) { ans|=(1<<i); now = son[now][1-id]; } else now = son[now][id]; } return ans;}map<int,int>mp;int main(){ ohMyLove; int n,m; while(~scanf("%d%d",&n,&m)) { mp.clear(); int x; init(); for(int i=1; i<=n; i++) { scanf("%d",&x); if(mp[x]==0) Insert(x); mp[x]=1; } int y=0; for(int i=1; i<=m; i++) { scanf("%d",&x); y^=x; printf("%d\n",query(y)); } } return 0;}
阅读全文
0 0
- codeforces 842D. Vitya and Strange Lesson
- Codeforces 842D Vitya and Strange Lesson
- Codeforces 842 D Vitya and Strange Lesson
- CodeForces 842D Vitya and Strange Lesson
- Codeforces 842 D. Vitya and Strange Lesson (trie)
- Codeforces 842 D Vitya and Strange Lesson 线段树
- D. Vitya and Strange Lesson
- Codeforces Round #430 (Div. 2) D. Vitya and Strange Lesson
- Codeforces Round #430 (Div. 2) D. Vitya and Strange Lesson
- Codeforces Round #430 (Div. 2) D. Vitya and Strange Lesson
- Codeforces Round #430 (Div. 2) D. Vitya and Strange Lesson
- [Codeforces 842D Vitya and Strange Lesson]异或字典树
- Codeforces 842D Vitya and Strange Lesson【逆向思维+字典树查询亦或最小值】
- Codeforces 842 D Vitya and Strange Lesson 线段树 (未理解透)
- CF 842D Vitya and Strange Lesson 01Trie(mex)
- 【Codeforces Round #430 (Div. 2) D】 D. Vitya and Strange Lesson ("带lazy" 的字典树)
- Codeforces Round #430 (Div. 2) D. Vitya and Strange Lesson [trie]
- Codeforces Round #430 (Div. 2):D. Vitya and Strange Lesson(模拟建树)
- Zookeeper 知识
- javascript的基本数据类型以及转换
- 微信小程序-----安装,编写第一个小程序和运行到手机端
- tarjan模板
- java版本区别
- codeforces 842D. Vitya and Strange Lesson
- java中的异常处理机制(2)
- 最实用的 Linux 命令行使用技巧
- 日语
- Leetcode OJ 22 Generate Parentheses [Medium]
- 通用数据结构关系
- 001_Linux常用命令 之ls、mkdir、cd、pwd、rmdir、rm、cp、mv、ln
- springmvc入门
- 51nod1103-抽屉原理-N的倍数