Codeforces Round #430 (Div. 2) D. Vitya and Strange Lesson
来源:互联网 发布:虚拟机网络没有连接 编辑:程序博客网 时间:2024/05/29 21:18
从高位到低位建一个01trie
每次对序列异或x
实际上只要把新的x异或上前面的所有x再找就可以了
假如原序列中没有x那就是0
有的话就找一遍
尽量往小的跑 满了的话就再往上
#include <iostream>#include <algorithm>#include <sstream>#include <string>#include <queue>#include <cstdio>#include <map>#include <set>#include <utility>#include <stack>#include <cstring>#include <cmath>#include <vector>#include <ctime>#include <bitset>using namespace std;#define pb push_back#define sd(n) scanf("%d",&n)#define sdd(n,m) scanf("%d%d",&n,&m)#define sddd(n,m,k) scanf("%d%d%d",&n,&m,&k)#define sld(n) scanf("%lld",&n)#define sldd(n,m) scanf("%lld%lld",&n,&m)#define slddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)#define sf(n) scanf("%lf",&n)#define sff(n,m) scanf("%lf%lf",&n,&m)#define sfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k)#define ss(str) scanf("%s",str)#define ans() printf("%d",ans)#define ansn() printf("%d\n",ans)#define anss() printf("%d ",ans)#define lans() printf("%lld",ans)#define lanss() printf("%lld ",ans)#define lansn() printf("%lld\n",ans)#define fansn() printf("%.10f\n",ans)#define r0(i,n) for(int i=0;i<(n);++i)#define r1(i,e) for(int i=1;i<=e;++i)#define rn(i,e) for(int i=e;i>=1;--i)#define rsz(i,v) for(int i=0;i<(int)v.size();++i)#define szz(x) ((int)x.size())#define mst(abc,bca) memset(abc,bca,sizeof abc)#define lowbit(a) (a&(-a))#define all(a) a.begin(),a.end()#define pii pair<int,int>#define pli pair<ll,int>#define mp make_pair#define lrt rt<<1#define rrt rt<<1|1#define X first#define Y second#define PI (acos(-1.0))#define sqr(a) ((a)*(a))typedef long long ll;typedef unsigned long long ull;const int mod = 1000000000+7;const double eps=1e-9;const int inf=0x3f3f3f3f;const ll infl = 10000000000000000;const int maxn= 300000+10;const int maxm = 10000+10;int in(int &ret){ char c; int sgn ; if(c=getchar(),c==EOF)return -1; while(c!='-'&&(c<'0'||c>'9'))c=getchar(); sgn = (c=='-')?-1:1; ret = (c=='-')?0:(c-'0'); while(c=getchar(),c>='0'&&c<='9')ret = ret*10+(c-'0'); ret *=sgn; return 1;}int ch[maxn*40][2];int cnt[maxn*40];bool bo[maxn];int tot;void update(int x,int w,int o){ if(w==-1)return; cnt[o]++; int now = (x>>w)&1; if(!ch[o][now])ch[o][now] = ++tot; update(x,w-1,ch[o][now]);}int query(int x,int w,int o){ int now = (x>>w)&1; if(!w) { if(ch[o][0^now]==0)return 0; if(ch[o][1^now]==0)return 1; } int idx = ch[o][0^now]; if(idx==0)return 0; if(cnt[idx]<(1<<w))return query(x,w-1,idx); if(ch[o][1^now]==0)return 1<<w; return (1<<w) + query(x,w-1,ch[o][1^now]);}int main(){#ifdef LOCAL freopen("input.txt","r",stdin);// freopen("output.txt","w",stdout);#endif // LOCAL int n,m; sdd(n,m); r1(i,n) { int x;sd(x); if(bo[x])continue; bo[x]=1; update(x,20,0); } int x = 0 ; r1(i,m) { int k;sd(k); x^=k; int ans; if(bo[x])ans = query(x,20,0); else ans = 0; ansn(); } return 0;}
阅读全文
0 0
- 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 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(模拟建树)
- Codeforces Round #430 (Div. 2) D. Vitya and Strange Lesson(01Trie)
- Codeforces Round #430 (Div. 2) D.Vitya and Strange Lesson 异或 01字典树补集最小
- 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 Round #430-01字典树&类异或最大值-D. Vitya and Strange Lesson
- D. Vitya and Strange Lesson
- Codeforces 842 D. Vitya and Strange Lesson (trie)
- Codeforces 842 D Vitya and Strange Lesson 线段树
- Code Forces 824D Round#430 Div2D:Vitya and Strange Lesson :01字典树
- 根据页面地址拼接页面内部获取到的地址
- Hibernate4 hello案例
- input框 placeholder变色,及去掉苹果手机默认input样式,css去除点击阴影
- book1 unit3 after-class reading 2 : How to Talk to Anyone, Anytime, Anywhere
- 领域驱动核心概念总结
- Codeforces Round #430 (Div. 2) D. Vitya and Strange Lesson
- 2017第九届北京空气净化及水净化、北京国际节能减排展览会会刊
- 842C Ilya And The Tree
- 欢迎使用CSDN-markdown编辑器
- 偶数个3
- 网络流24题-7
- Spark源码系列(四)图解作业生命周期
- 关于更换JDK后启动Eclipse时提示版本过低的一个解决方案
- mac磁盘清理的几种方法