字典树。

比较经典的题目了。把每一个数字都插入到字典树中,询问的时候如果$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. dedecms模板中使用php代码

    {dede:php} echo “test”: {/dede:php} 使用这段代码之前要在后台的系统--系统基本参数--其它选项 里找到 模板引擎禁用标签: php  将其删除

  2. smtp中ehlo的使用

    以前玩smtp的时候申明都是用的helo,最近在整理邮件服务的时候,才知道还有一个叫做ehlo的(太落后了). google了一下,了解了基本上是这么个情况:ehlo是对helo的扩展,即extend ...

  3. socket网络编程快速上手(二)——细节问题(2)

    2.TCP数据包接收问题 对初学者来说,很多都会认为:客户端与服务器最终的打印数据接收或者发送条数都该是一致的,1000条发送打印,1000条接收打印,长度都为1000.但是,事实上并不是这样,发送打 ...

  4. List remove操作注意问题

    public static void main(String[] args) { // TODO Auto-generated method stub List<String> list ...

  5. eclipse配置自动提示EXTJS和jQurey

    extjs-2.3.0下载地址1:http://dev.sencha.com/deploy/ext-2.3.0.zip 下载地址2:http://www.sencha.com/products/ext ...

  6. MFC中菜单变灰的问题

    MFC中菜单变灰 方法1:有UpdateCmdUI句柄时 定义一个BOOL变量m_b来标志菜单项是否有效, 该菜单项响应UPDATE_COMMAND_UI消息,在消息处理函数中pCmdUI->E ...

  7. hdu4277 USACO ORZ

    USACO ORZ Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  8. Winform 让跨线程访问变得更简单

    Winform 让跨线程访问变得更简单 前言 由于多线程可能导致对控件访问的不一致,导致出现问题.C#中默认是要线程安全的,即在访问控件时需要首先判断是否跨线程,如果是跨线程的直接访问,在运行时会抛出 ...

  9. CF 327E(Axis Walking-状态压缩Dp-lowbit的使用)

    E. Axis Walking time limit per test 3 seconds memory limit per test 512 megabytes input standard inp ...

  10. api 和 abi的区别

    156down vote API: Application Program Interface This is the set of public types/variables/functions ...