Codeforces
来源:互联网 发布:java web直播源码 编辑:程序博客网 时间:2024/05/21 10:11
Codeforces - 842D - Vitya and Strange Lesson
题意可以很轻松的转化为:每个询问给定一个整数
可以先将数组中的所有元素放入01Trie
中,每次询问,对于 Trie
的
#include<bits/stdc++.h>using namespace std;typedef long long ll;const int N=3e5+7;int a[N];struct Trie{ int next[N*20][2],sz[N*20],L,root,M=18; int newnode() { next[L][1]=next[L][0]=-1; sz[L]=0; return L++; } void init() { L=0; root=newnode(); } int query(int x) { int now=root,res=0; for(int i=M;i>=0;--i) { int b=((x>>i)&1); if(next[now][b]==-1) return res; if(sz[next[now][b]]<(1<<i)) now=next[now][b]; else { res|=(1<<i); if(next[now][b^1]==-1) return res; now=next[now][b^1]; } } return res; } void insert(int x) { int now=root; ++sz[now]; for(int i=M;i>=0;--i) { int b=(x>>i)&1; if(next[now][b]==-1) next[now][b]=newnode(); now=next[now][b]; ++sz[now]; } if(sz[now]>1) { now=root; --sz[now]; for(int i=M;i>=0;--i) { int b=(x>>i)&1; now=next[now][b]; --sz[now]; } } }};Trie t;int main(){ int n,m; scanf("%d%d",&n,&m); t.init(); for(int i=1;i<=n;++i) { int k; scanf("%d",&k); t.insert(k); } int now=0; for(int i=1;i<=m;++i) { int k; scanf("%d",&k); now^=k; printf("%d\n",t.query(now)); } return 0;}
阅读全文
0 0
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- 淘客超人介绍
- STM32CubeMX基于SD卡的FATFS文件系统测试(附源码)
- 一句话木马,小马,大马,混淆一句话木马
- [目标检测]YOLO原理
- springboot jar方式启动修改端口
- Codeforces
- linux和windows下,C/C++的sleep函数
- SQL server image截取部分数据,转int类型
- WOJ1024-Exploration
- 无锁单线程内存池
- WebSocket刨根问底(四)之五子棋大战江湖
- 怎样在不处理的情况下在ABBYY FineReader 12中添加图像
- 在unity中有关VRTK的射线使用
- FormData 对象的使用