Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset
题目链接:Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset
题意:
给你一些操作,往一个集合插入和删除一些数,然后?x让你找出与x异或后的最大值
题解:
trie树xjb搞就行,每次要贪心,尽量满足高位为1.
#include<bits/stdc++.h>
#define F(i,a,b) for(int i=a;i<=b;i++)
using namespace std; namespace trie
{
const int N=(2e5+)*;
int tr[N][],ed=-,cnt[N];
void nw(){cnt[++ed]=,tr[ed][]=tr[ed][]=;}
void update(int x,int c,int now=)
{
for(int i=;i>=;i--)
{
int v=x>>i&;
if(!tr[now][v])nw(),tr[now][v]=ed;
now=tr[now][v];
cnt[now]+=c;
}
}
int ask(int x,int now=,int ans=)
{
for(int i=;i>=;i--)
{
int v=x>>i&;
if(!cnt[tr[now][v^]])now=tr[now][v];
else now=tr[now][v^],ans|=<<i;
}
return ans;
}
}
using namespace trie;
int main()
{
int n,x;char op[];
scanf("%d",&n);
nw(),update(,);
F(i,,n)
{
scanf("%s%d",op,&x);
if(op[]=='+')update(x,);
else if(op[]=='-')update(x,-);
else printf("%d\n",ask(x));
}
return ;
}
Codeforces Round #367 (Div. 2) 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 Trie
题目链接: http://codeforces.com/contest/706/problem/D D. Vasiliy's Multiset time limit per test:4 second ...
- 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 ...
- Codeforces Round #367 (Div. 2)D. Vasiliy's Multiset (字典树)
D. Vasiliy's Multiset time limit per test 4 seconds memory limit per test 256 megabytes input standa ...
- 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 ...
- Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset(01字典树求最大异或值)
http://codeforces.com/contest/706/problem/D 题意:有多种操作,操作1为在字典中加入x这个数,操作2为从字典中删除x这个数,操作3为从字典中找出一个数使得与给 ...
- 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 ...
随机推荐
- JavaEE XML StAX创建
StAX创建XML文档 @author ixenos 1. 如果通过DOM树来创建XML文件时,发现这个DOM树没有其他用途,那么这种方式就不是很高效,这时我们可以使用StAX API直接将XML树写 ...
- install plugin elasticsearch-analysis-ik
1.github下载分词器插件(请各位下载自己elasticsearch相对应的版本,否则会有兼容性问题) https://github.com/medcl/elasticsearch-analysi ...
- Intellij 快捷键
11ctrl+F12 类似于eclipse 的outline 显示出当前类的所有方法. ctrl+H 查看当前类或者方法的集成结构 ctrl+E 查看最近使用的文件 Ctrl+J 自动完成提示 C ...
- CodeForces 659F Polycarp and Hay
并查集,$dfs$. 从大的数字往里加,每加一个数字合并一下连通块,判断连通块内数字个数是否够,以及k能不能被当前加入的数字整除.然后$dfs$一下构造答案. #pragma comment(link ...
- awk学习笔记二:调用shell、文件执行(转)
awk 'BEGIN {print "Hello"}' 不操作文件直接处理数据流 要调用shell则可以用管道命令 如,打印日期awk 'BEGIN {"date&quo ...
- PHP微信支付开发之扫描支付(模式二)后如何回调
其实在写这篇文章的时候感觉自己已经落伍了,不过笔者在百度上搜索"微信支付开发之扫描支付(模式二)后如何回调"寻找答案时,发现依旧有很多朋友没有解决这个问题,所以就把自己的解决思路分 ...
- ES 6 : 数组的扩展
1.Array.from() Array.from方法用于将两类对象转为真正的数组:类似数组的对象和可遍历(iterable)对象. 下面是一个类似数组的对象,Array.from将它转为真正的数组. ...
- 为什么Intent传递对象的时候必须要将对象序列化呢?
Intent可以算是四大组件之间的胶水,比如在Activity1与Activity2之间传递对象的时候,必须要将对象序列化, 可是为什么要将对象序列化呢? Intent在启动其他组件时,会离开当前应用 ...
- Python学习笔记——基础篇【第六周】——hashlib模块
常用模块之hashlib模块 用于加密相关的操作,3.x里代替了md5模块和sha模块,主要提供 SHA1, SHA224, SHA256, SHA384, SHA512 ,MD5 算法 import ...
- [河南省ACM省赛-第四届] 序号互换 (nyoj 303)
相似与27进制的转换 #include<iostream> #include<cstdio> #include<cstring> #include<strin ...