字典树。

比较经典的题目了。把每一个数字都插入到字典树中,询问的时候如果$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. MongoDB应用介绍之前

    MongoDb企业应用实战(一) 写在MongoDB应用介绍之前   故事背景: 本人有幸,经老友( 现为x知名快递公司技术总监 ) 推荐进入中国前三大民营快递公司之一工作,在此非常感谢他,在此也非常 ...

  2. 计算image 积分图

    // testopencv.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <opencv2\opencv.hpp& ...

  3. intellij idea 学习

      intellij idea是一个java的ide.由jetbrain开发.     intellij idea快捷键 快捷键 说明 备注 Ctrl+N 快速导航到类 类似于Resharper中的C ...

  4. 前端开发的使用服务器环境开源项目 D2Server 可替代Apache

    推荐一个前端开发的使用服务器环境开源项目 D2Server 可替代Apache   攻欲善其事,必先利其器.前端开发,编辑器我们有了Sublime Text2,配置Server环境用……你可能会选择A ...

  5. HTML5学习+javascript学习:打飞机游戏Service层Control层+源码

    2.Service层 如前所述,Service层是Control层与Model层之间桥接的一层,它拥有所有要在屏幕上显示的实体(除了背景)的引用 我们知道,当游戏运行时,随时都可能发生碰撞,随时都可能 ...

  6. 一步步学习Python-django开发-Mac下搭建Python-Django环境

    首先确定学习那一个版本,以之前对Python的接触,Python2.x 的版本仍然占据很大的市场.但作为初学者我还是决定学习新的版本,相信未来会逐渐转向3.x版本的. 其实搭建Python不是一件很难 ...

  7. Arduino live weather broadcasting 实时天气站

    Live broadcasting with arduino get a pc , make it run linux. make arduino catch the weather sensor a ...

  8. 苹果页面启动icon大小(57*57 114*114)

    苹果页面启动icon大小(57*57   114*114)做的时候要弄成正方形

  9. windows下安装Django

    因为Django本身是由Python编写,所以先要安装Python.下载地址(可以根据读者当前版本自行下载):http://www.python.org/download/releases/3.3.4 ...

  10. MP4视频编码器

    用 HTML5 播放视频,最流行的视频格式非 MP4莫属, 所有最新浏览器都支持; MP4 带有 H.264 视频编码和 AAC 音频编码的 MPEG 4 文件: 以前做过一个把其它编码格式的视频转成 ...