trie树 Codeforces Round #367 D Vasiliy's Multiset
// trie树 Codeforces Round #367 D Vasiliy's Multiset
// 题意:给一个集合,初始有0,+表示添加元素,-去除元素,?询问集合里面与x异或最大的值
// 思路:思路很好想,建立trie树,再贪心当前位是1则选0,0则选1 #include <bits/stdc++.h>
using namespace std;
#define LL long long
const double inf = 123456789012345.0;
const LL MOD =100000000LL;
const int N =1e7+;
#define clc(a,b) memset(a,b,sizeof(a))
const double eps = 1e-;
void fre() {freopen("in.txt","r",stdin);}
void freout() {freopen("out.txt","w",stdout);}
inline int read() {int x=,f=;char ch=getchar();while(ch>''||ch<'') {if(ch=='-') f=-; ch=getchar();}while(ch>=''&&ch<='') {x=x*+ch-'';ch=getchar();}return x*f;}
int d[N][];
int cnt=;//节点下标
int num[N];
void update(int x){
int k=;
for(int i=;i>=;i--){
if(d[k][(x>>i)&]==) d[k][(x>>i)&]=++cnt;
k=d[k][(x>>i)&];
num[k]++;
}
} void update1(int x){
int k=;
num[]--;
for(int i=;i>=;i--){
k=d[k][(x>>i)&];
num[k]--;
}
} int query(int x){
int k=;
int ans=;
for(int i=;i>=;i--){
int t=(x>>i)&;
if(num[d[k][^t]]) k=d[k][^t],ans+=(<<i);
else k=d[k][t];
}
return ans;
} int main(){
int q;
scanf("%d",&q);
update();
while(q--){
char s[];
int x;
scanf("%s%d",s,&x);
if(s[]=='+') update(x);
else if(s[]=='-') update1(x);
else {
int ans=query(x);
printf("%d\n",ans);
}
}
return ;
}
trie树 Codeforces Round #367 D Vasiliy's Multiset的更多相关文章
- 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 ...
- Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset
题目链接:Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset 题意: 给你一些操作,往一个集合插入和删除一些数,然后?x让你找出与x异或后的最大值 ...
- Codeforces Round #367 (Div. 2) (A,B,C,D,E)
Codeforces Round 367 Div. 2 点击打开链接 A. Beru-taxi (1s, 256MB) 题目大意:在平面上 \(n\) 个点 \((x_i,y_i)\) 上有出租车,每 ...
- Codeforces Round #367 (Div. 2) C. Hard problem(DP)
Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...
- Codeforces Round #367 (Div. 2) B. Interesting drink (模拟)
Interesting drink 题目链接: http://codeforces.com/contest/706/problem/B Description Vasiliy likes to res ...
- Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)
Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...
- 十字链表 Codeforces Round #367 E Working routine
// 十字链表 Codeforces Round #367 E Working routine // 题意:给你一个矩阵,q次询问,每次交换两个子矩阵,问最后的矩阵 // 思路:暴力肯定不行.我们可以 ...
- Codeforces Round #367 (Div. 2) C. Hard problem
题目链接:Codeforces Round #367 (Div. 2) C. Hard problem 题意: 给你一些字符串,字符串可以倒置,如果要倒置,就会消耗vi的能量,问你花最少的能量将这些字 ...
- 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 ...
随机推荐
- Linux系统与性能监控
原文地址:http://kerrigan.sinaapp.com/post-7.html Linux System and Performance Monitoring http://www.hous ...
- Linux和Linux之间共享目录
1.Linux 服务器端NFS服务器的配置 以root身份登陆Linux服务器,编辑/etc目录下的共享目录配置文件exports,指定共享目录及权限等. 执行如下命令编辑文件/etc/exports ...
- 256. Paint House
题目: There are a row of n houses, each house can be painted with one of the three colors: red, blue o ...
- ifdebug
#if DEBUG 首先,大小写不能写错. 其次,解决方案配置设为:Debug,才会执行该语句,如果在条件里面搭配Debug.Assert等,效果甚佳.而如果要设置为Release模式,就不会执行条件 ...
- chrome调试、移动端调试
chrome 32版本后,添加 DevTools for Mobile 插件就可远程手机调试 DevTools for Mobile插件安装https://support.google.com/chr ...
- OLAP、OLTP的介绍和比较
OLTP与OLAP的介绍 数据处理大致可以分成两大类:联机事务处理OLTP(on-line transaction processing).联机分析处理OLAP(On-Line Analytical ...
- Js 读写cookies
//写cookies函数 function setCookie(name, value)//两个参数,一个是cookie的名子,一个是值 { var Days = 30; //此 cookie 将被保 ...
- php通过curl调用jpush接口实现消息的推送
public function actionNotifyto() { //$regid = $_REQUEST['regid']; $url = 'https://api.jpush.cn/v3/pu ...
- cocos2d-x之 CCSpriteBatchNode 用法总结
例子1: CCSpriteBatchNode* batch = [CCSpriteBatchNode batchNodeWithFile:@"table.png"]; ...
- Android Configuration change引发的问题及解决方法(转)
之前在学习Fragment和总结Android异步操作的时候会在很多blog中看到对Configuration Change的讨论,以前做的项目都是固定竖屏的,所以对横竖屏切换以及横竖屏切换对程序有什 ...