字典树。

比较经典的题目了。把每一个数字都插入到字典树中,询问的时候如果$x$的第$i$位是$p$,那么尝试着在字典树上往$pXOR1$的节点走下去,没有$pXOR1$节点的话再走$p$的。删除操作的话可以记录一下每一个节点出现了几次,$Insert$的时候$s[p].cnt++$,$Delete$的时候$s[p].cnt--$,如果发现$s[p].cnt==0$,那么将以$p$为根的树全删了,也就是$p$的$father$到$p$的路标为$-1$。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
} const int maxn=;
struct X { int nx[], cnt; }s[*maxn];
int n,x,h,sz; char op[]; int add()
{
sz++; s[sz].cnt=;
s[sz].nx[]=s[sz].nx[]=-;
return sz;
} void Insert(int x)
{
int p=;
for(int i=;i>=;i--)
{
if((<<i)&x) h=; else h=;
if(s[p].nx[h]==-) s[p].nx[h]=add();
p=s[p].nx[h]; s[p].cnt++;
}
} void Delete(int x)
{
int p=;
for(int i=;i>=;i--)
{
if((<<i)&x) h=; else h=;
int t=p; p=s[p].nx[h]; s[p].cnt--;
if(s[p].cnt==) s[t].nx[h]=-;
}
} int Find(int x)
{
int p=,res=;
for(int i=;i>=;i--)
{
if((<<i)&x) h=; else h=;
if(s[p].nx[h^]!=-) p=s[p].nx[h^],res=res+(<<i);
else if(s[p].nx[h]!=-)p=s[p].nx[h];
}
return res;
} int main()
{
scanf("%d",&n);
s[].nx[]=s[].nx[]=-; s[].cnt=;
sz=; Insert();
for(int i=;i<=n;i++)
{
scanf("%s%d",op,&x);
if(op[]=='+') Insert(x);
else if(op[]=='-') Delete(x);
else printf("%d\n",Find(x));
}
return ;
}

CodeForces 706D Vasiliy's Multiset的更多相关文章

  1. 【字典树】【贪心】Codeforces 706D Vasiliy's Multiset

    题目链接: http://codeforces.com/contest/706/problem/D 题目大意: 三种操作,1.添加一个数,2.删除一个数,3.查询现有数中与x异或最大值.(可重复) 题 ...

  2. Codeforces 706D Vasiliy's Multiset(可持久化字典树)

    [题目链接] http://codeforces.com/problemset/problem/706/D [题目大意] 要求实现一个集合中的三个操作,1:在集合中加入一个元素x,2:从集合中删除一个 ...

  3. CodeForces 706D Vasiliy's Multiset (字典树查询+贪心)

    题意:最开始的时候有一个集合,集合里面只有一个元素0,现在有q次操作,操作分为3种: + x: 表示向集合中添加一个元素x - x:表示删除集合中值为x的一个元素 ? x:表示查询集合中与x异或的最大 ...

  4. codeforces 706D D. Vasiliy's Multiset(trie树)

    题目链接: D. Vasiliy's Multiset time limit per test 4 seconds memory limit per test 256 megabytes input ...

  5. Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset(可持久化Trie)

    D. Vasiliy's Multiset time limit per test 4 seconds memory limit per test 256 megabytes input standa ...

  6. Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset (0/1-Trie树)

    Vasiliy's Multiset 题目链接: http://codeforces.com/contest/706/problem/D Description Author has gone out ...

  7. trie树 Codeforces Round #367 D Vasiliy's Multiset

    // trie树 Codeforces Round #367 D Vasiliy's Multiset // 题意:给一个集合,初始有0,+表示添加元素,-去除元素,?询问集合里面与x异或最大的值 / ...

  8. Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset

    题目链接:Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset 题意: 给你一些操作,往一个集合插入和删除一些数,然后?x让你找出与x异或后的最大值 ...

  9. Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset Trie

    题目链接: http://codeforces.com/contest/706/problem/D D. Vasiliy's Multiset time limit per test:4 second ...

随机推荐

  1. [转]Inspecting Obj-C parameters in gdb

    Since the addition of i386 and x86_64 to the Mac OS’s repertoire several years back, remembering whi ...

  2. c语言,string库函数strstr实现

    说明: 原型:char *strstr(char *haystack, char *needle); 用法:#include <string.h> 功能:从字符串haystack中寻找ne ...

  3. PL/SQL配置大小写转换等快捷键

    Tools(工具) --> Preferences(首选项) --> Key Configuration(键配置) 然后修改自己需要的快捷键方式 作者:itmyhome

  4. 我的Pandas应用场景

    声明 工作后,很不幸的成为了团队中的QA.QA这个角色吧,说起来高大上,实际很苦逼,一句话概括一下:吃力不讨好!作为新人,公司每月一分钱没少我,至少现在跟开发的待遇是一样的,所以我还是得兢兢业业的对待 ...

  5. NHibernate Session-per-request and MiniProfiler.NHibernate

    NHibernate Session-per-request and MiniProfiler.NHibernate 前言 1.本文以mvc3为例,借鉴开源项目 NerdDnner项目完成nhiber ...

  6. 实现了一个简单的key-value存储系统

    实现了一个简单的key-value存储系统 源码下载: kvfs.rar 正文: 所谓的Key-Value就是每次存储一个数据时,是根据Key进行索引存储的.为了实现Key的快速查找功能,我使用了B- ...

  7. Excel 开发概述

    浅谈Excel开发:一 Excel 开发概述 做Office相关的开发工作快一年多了,在这一年多里,在插件的开发中遇到了各种各样的问题和困难,还好同事们都很厉害,在和他们的交流讨论中学到了很多的知识. ...

  8. .net下灰度模式图像

    .net下灰度模式图像在创建Graphics时出现:无法从带有索引像素格式的图像创建graphics对象 问题的解决方案. Posted on 2013-07-13 14:23 Imageshop 阅 ...

  9. hdu 4198 Quick out of the Harbour(BFS+优先队列)

    题目链接:hdu4198 题目大意:求起点S到出口的最短花费,其中#为障碍物,无法通过,‘.’的花费为1 ,@的花费为d+1. 需注意起点S可能就是出口,因为没考虑到这个,导致WA很多次....... ...

  10. Fedora 19的U盘安装 以及简单配置

    一.Fedora19的U盘安装 2013年7月3日,Fedora 19正式版发布.Fedora 19除了GNOME桌面版之外,还提供了KDE定制版.LXDE定制版等,有兴趣的网友可以在其官网上下载试用 ...