Vasiliy's Multiset CodeForces -706D || 01字典树模板
就是一个模板
注意这题有一个要求:有一个额外的0一直保持在集合中
#include<cstdio>
#include<algorithm>
using namespace std;
const int _LEN=;
//上限为2^30-1,即二进制最多30位
int lft[];
namespace Trie
{
int ch[][],sz[];
int mem;
void insert(int x,int cur)
{
int i;bool t;
for(i=_LEN-;i>=;--i)
{
t=x&lft[i];
if(!ch[cur][t]) ch[cur][t]=++mem;
++sz[cur];cur=ch[cur][t];
}
++sz[cur];
}
int query(int x,int cur)
{
int i,ans=;bool t;
for(i=_LEN-;i>=;--i)
{
t=x&lft[i];
if(sz[ch[cur][t^]]) ans|=lft[i],cur=ch[cur][t^];
else cur=ch[cur][t];
}
return ans;
}
void erase(int x,int cur)
{
int i;bool t;
for(i=_LEN-;i>=;--i)
{
t=x&lft[i];
--sz[cur];cur=ch[cur][t];
}
--sz[cur];
}
};
int root;
char ss[];
int main()
{
int i,q,x;
lft[]=;
for(i=;i<=_LEN;i++) lft[i]=lft[i-]<<;
root=++Trie::mem;Trie::insert(,root);
scanf("%d",&q);
while(q--)
{
scanf("%s%d",ss,&x);
if(ss[]=='+')
{
Trie::insert(x,root);
}
else if(ss[]=='-')
{
Trie::erase(x,root);
}
else if(ss[]=='?')
{
printf("%d\n",Trie::query(x,root));
}
}
return ;
}
Vasiliy's Multiset CodeForces -706D || 01字典树模板的更多相关文章
- Xor Sum---hdu4825(01字典树模板)
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4825 题意:有n个数m个查找,每个查找有一个数x, 从序列中找到一个数y,使得x异或y最大 ...
- Codeforces 706D Vasiliy's Multiset(可持久化字典树)
[题目链接] http://codeforces.com/problemset/problem/706/D [题目大意] 要求实现一个集合中的三个操作,1:在集合中加入一个元素x,2:从集合中删除一个 ...
- codeforces 706D (字典树)
题目链接:http://codeforces.com/problemset/problem/706/D 题意:q次操作,可以向多重集中增添,删除,询问异或最大值. 思路:转化为二进制用字典树存储,数字 ...
- Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树
A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...
- HDU 4825 Xor Sum (模板题)【01字典树】
<题目链接> 题目大意: 给定n个数,进行m次查找,每次查找输出n个数中与给定数异或结果最大的数. 解题分析: 01字典树模板题,01字典树在求解异或问题上十分高效.利用给定数据的二进制数 ...
- [CodeForces948D]Perfect Security(01字典树)
Description 题目链接 Solution 01字典树模板题,删除操作用个数组记录下就行了 Code #include <cstdio> #include <algorith ...
- codeforces 842 D. Vitya and Strange Lesson(01字典树+思维+贪心)
题目链接:http://codeforces.com/contest/842/problem/D 题解:像这种求一段异或什么的都可以考虑用字典树而且mex显然可以利用贪心+01字典树,和线段树差不多就 ...
- Codeforces 979 D. Kuro and GCD and XOR and SUM(异或和,01字典树)
Codeforces 979 D. Kuro and GCD and XOR and SUM 题目大意:有两种操作:①给一个数v,加入数组a中②给出三个数x,k,s:从当前数组a中找出一个数u满足 u ...
- Choosing The Commander CodeForces - 817E (01字典树+思维)
As you might remember from the previous round, Vova is currently playing a strategic game known as R ...
随机推荐
- [Angular] Expose Angular Component Logic Using State Reducers
A component author has no way of knowing which state changes a consumer will want to override, but s ...
- anaconda中新rdkit安装
1. 执行 conda create -c rdkit -n my-rdkit-env rdkit 该步骤经测试发现需FQ,而模拟器无法完成FQ(至少我不知道方法), 因此在本机上配置好环境后复制粘贴 ...
- C语言的各种位运算符的操作简述
运算符: 算术运算符: + , - , * , / , % , ++ , -- 符合运算符: += , *= , /= , %= 条件运算符: ? : 关系运算符: == , >= , < ...
- Android调用本地WebService
package com.example.testinvokewebservice; import org.ksoap2.SoapEnvelope; import org.ksoap2.serializ ...
- Hackrank Candies DP
题目链接:传送门 题意: n个学生站一行,老师给每个学生发至少一个糖 相邻学生,a[i] > a[i-1] 的话,那么右边学生的糖一定要发得比左边学生的糖多 问你满足条件这个老师总共最少的发多少 ...
- Delphi的函数指针
不求全面,先留个爪: TNotifyEvent = procedure(Sender: TObject) of object; TMethod = record Code, Data: Pointer ...
- 20170212-备份ABAP程序
把生产机上所有后续开发的CBO程序都备份下来.以备急用! 用过2种方法:1.写BDC程序,模拟 TCODE:SE38 -->Program --> Utilities(M)-->Mo ...
- 双系统xp和ubuntu,删除ubuntu
1:下载MbrFix.exe 2:进入c盘,命令MbrFix /drive 0 fixmbr
- [转]python的find()方法
描述 Python find() 方法检测字符串中是否包含子字符串 str ,如果指定 beg(开始) 和 end(结束) 范围,则检查是否包含在指定范围内,如果包含子字符串返回开始的索引值,否则返回 ...
- asp.net mvc5 使用百度ueditor 本编辑器完整示例(上)
最近做一个项目,用到了百度ueditor富文本编辑器,功能强大,在线编辑文档,上传图片\视频.附件. MVC 模型的控制器准备: 1.建立模型. 在项目中Model 文件夹中建立 文章 模型,注意如果 ...