【CodeForces - 706D】Vasiliy's Multiset(01字典树)

题干:

Author has gone out of the stories about Vasiliy, so here is just a formal task description.

You are given q queries and a multiset A, initially containing only integer 0. There are three types of queries:

  1. "+ x" — add integer x to multiset A.
  2. "- x" — erase one occurrence of integer x from multiset A. It's guaranteed that at least one x is present in the multiset A before this query.
  3. "? x" — you are given integer x and need to compute the value , i.e. the maximum value of bitwise exclusive OR (also know as XOR) of integer x and some integer y from the multiset A.

Multiset is a set, where equal elements are allowed.

Input

The first line of the input contains a single integer q (1 ≤ q ≤ 200 000) — the number of queries Vasiliy has to perform.

Each of the following q lines of the input contains one of three characters '+', '-' or '?' and an integer xi (1 ≤ xi ≤ 109). It's guaranteed that there is at least one query of the third type.

Note, that the integer 0 will always be present in the set A.

Output

For each query of the type '?' print one integer — the maximum value of bitwise exclusive OR (XOR) of integer xi and some integer from the multiset A.

Example

Input

10
+ 8
+ 9
+ 11
+ 6
+ 1
? 3
- 8
? 3
? 8
? 11

Output

11
10
14
13

Note

After first five operations multiset A contains integers 0, 8, 9, 11, 6 and 1.

The answer for the sixth query is integer  — maximum among integers  and .

题目大意:

维护一个初始时只有元素0的多重集,有三种操作

1  x: 添加一个数x

2  x: 删除一个数x

3  x: 询问一个数x与这个集合中的某一个元素的异或值最大是多少。

总共q次操作,每次操作是xi  (1 ≤ xi ≤ 1e9,1 ≤ q ≤ 200 000)

解题报告:

直接01字典树,注意刚开始需要先插入0.再就是数组需要开大一些左右,2e5是不够的。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define FF first
#define SS second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 1e7 + 5;
int tr[MAX][2],tot,num[MAX];
void ins(int x) {int rt = 0;for(int bit = 31; bit>=0; bit--) {int tar = (x&(1<<bit)) > 0 ? 1 : 0;if(tr[rt][tar] == 0) tr[rt][tar] = ++tot;rt=tr[rt][tar]; num[rt]++;}
}
void del(int x) {int rt = 0;for(int bit = 31; bit>=0; bit--) {int tar = (x&(1<<bit)) > 0 ? 1 : 0;rt=tr[rt][tar]; num[rt]--;}
}
int cal(int x) {int res = 0,rt = 0;for(int bit = 31; bit>=0; bit--) {int tar = (x&(1<<bit)) > 0 ? 1 : 0;if(num[tr[rt][!tar]] > 0) res |= (1<<bit),rt=tr[rt][!tar];else rt = tr[rt][tar];if(rt == 0) break;} return res;
}
int main()
{int q,x; char op[5];cin>>q;ins(0);while(q--) {scanf("%s%d",op,&x);if(op[0] == '+') ins(x);if(op[0] == '-') del(x);if(op[0] == '?') printf("%d\n",cal(x));}return 0 ;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/439609.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

详解自动驾驶仿真框架OpenCDA: An Open Cooperative Driving Automation Framework Integrated with Co-Simulation

本文介绍一款同时支持协同驾驶开发与测试、自动驾驶全栈开发 和 CARLA-SUMO联合仿真的开源框架 OpenCDA&#xff0c;论文已收录于 ITSC 2021。主要feature有&#xff1a; 支持CARLA-SUMO联合仿真&#xff0c;CARLA端主管环境渲染、传感器模拟、车辆动力&#xff0c;Sumo端主管…

JavaMonitor 监视器

为什么wait(), notify()和notifyAll()必须在同步方法或者同步块中被调用&#xff1f; 当一个线程需要调用对象的wait()方法的时候&#xff0c;这个线程必须拥有该对象的锁&#xff0c;接着它就会释放这个对象锁并进入等待状态直到其他线程调用这个对象上的notify()方法。同样的…

KITTI自动驾驶数据集可视化教程

本文介绍关于自动驾驶数据集KITTI的基本操作&#xff0c;包括Camera和LiDAR可视化教程&#xff0c;源码已上传&#xff1a;https://download.csdn.net/download/cg129054036/20907604 1. 数据准备 将 KITTI 数据 (calib, image_2, label_2, velodyne) 添加到 dataset/KITTI/ob…

重读经典《Quaternion kinematics for the error-state Kalman filter》

本文将介绍一篇关于 四元数运动学的误差卡尔曼滤波 经典论文。本文结构如下&#xff1a; 第1章四元数定义和性质介绍&#xff0c;包括&#xff1a;加法、减法、乘法&#xff08;矩阵表示&#xff09;、模、幂数、指数运算等。第2章旋转群定义和性质介绍&#xff0c;包括&#…

【CodeForces - 789C】Functions again(最大子段和变形,dp,思维)

题干&#xff1a; Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are wo…

一步步编写操作系统 55 CPL和DPL入门2

接上节。 图中第132行的jmp指令&#xff0c;段选择子为SELECTOR_CODE&#xff0c;其RPL的值为RPL0&#xff0c;RPL0定义在include/boot.inc中&#xff0c;其值为0。选择子的索引部分值为1&#xff0c;表示对应GDT中第1个段描述符&#xff0c;该描述符的DPL为0&#xff0c;&…

详解停车位检测算法 Vision-Based Parking-Slot Detection: A DCNN-Based Approach and a Large-Scale Benchmark

本文介绍一篇基于深度学习的停车位检测论文&#xff1a;DeepPS&#xff0c;作者同时公开了数据集ps2.0&#xff0c;工作很扎实&#xff0c;对于入门停车位检测很有帮助&#xff0c;论文发表在 IEEE T-IP 2018。 项目链接为&#xff1a;https://cslinzhang.github.io/deepps/ 0…

Monitor(管程)是什么意思?Java中Monitor(管程)的介绍

本篇文章给大家带来的内容是关于Monitor&#xff08;管程&#xff09;是什么意思&#xff1f;Java中Monitor&#xff08;管程&#xff09;的介绍&#xff0c;有一定的参考价值&#xff0c;有需要的朋友可以参考一下&#xff0c;希望对你有所帮助。 monitor的概念 管程&#x…

详解经典GPS辅助惯性导航论文 A GPS-aided Inertial Navigation System in Direct Configuration

本文介绍一篇 IMU 和 GPS 融合的惯性导航论文&#xff0c;重点是理解本文提出的&#xff1a;Dynamical constraints update、Roll and pitch updates 和 Position and heading updates。 论文链接为&#xff1a;https://www.sciencedirect.com/science/article/pii/S166564231…

详解停车位检测论文:Attentional Graph Neural Network for Parking-slot Detection

本文介绍一篇注意力图神经网络用于停车位检测论文&#xff0c;论文已收录于 RA-L2021。在之前的基于卷积神经网络的停车位检测方法中&#xff0c;很少考虑停车位标记点之间的关联信息&#xff0c;从而导致需要复杂的后处理。在本文中&#xff0c;作者将环视图中的标记点看作图结…

详解3D物体检测模型 SPG: Unsupervised Domain Adaptation for 3D Object Detection via Semantic Point Generation

本文对基于激光雷达的无监督域自适应3D物体检测进行了研究&#xff0c;论文已收录于 ICCV2021。 在Waymo Domain Adaptation dataset上&#xff0c;作者发现点云质量的下降是3D物件检测器性能下降的主要原因。因此论文提出了Semantic Point Generation (SPG)方法&#xff0c;首…

Waymo研发经理:《自动驾驶感知前沿技术介绍》

Waymo研发经理|自动驾驶感知前沿技术介绍这是Waymo研发经理&#xff08;VoxelNet作者&#xff09;的一个最新分享报告&#xff1a;《自动驾驶感知前沿技术介绍》。在这份报告里&#xff0c;介绍了Waymo在自动驾驶感知中五个研究方向的最新成果。 1. Overview of the autonomous…

几种常见软件过程模型的比较

瀑布模型 瀑布模型&#xff08;经典生命周期&#xff09;提出了软件开发的系统化的、顺序的方法。其流 程从用户需求规格说明开始&#xff0c;通过策划、建模、构建和部署的过程&#xff0c;最终提供一 个完整的软件并提供持续的技术支持。 优点&#xff1a; 1. 强调开发的…

两篇基于语义地图的视觉定位方案:AVP-SLAM和RoadMap

本文介绍两篇使用语义地图进行视觉定位的论文&#xff0c;两篇论文工程性很强&#xff0c;值得一学。 AVP-SLAM是一篇关于自动泊车的视觉定位方案&#xff0c;收录于 IROS 2020。论文链接为&#xff1a;https://arxiv.org/abs/2007.01813&#xff0c;视频链接为&#xff1a;ht…

【51Nod - 1270】数组的最大代价(dp,思维)

题干&#xff1a; 数组A包含N个元素A1, A2......AN。数组B包含N个元素B1, B2......BN。并且数组A中的每一个元素Ai&#xff0c;都满足1 < Ai < Bi。数组A的代价定义如下&#xff1a; &#xff08;公式表示所有两个相邻元素的差的绝对值之和&#xff09; 给出数组B&…

一步步编写操作系统 56 门、调用门与RPL序 1

小弟多次想把调用门和RPL分开单独说&#xff0c;但几次尝试都没有成功&#xff0c;我发现它们之间是紧偶合、密不可分&#xff0c;RPL的产生主要是为解决系统调用时的“越权”问题&#xff0c;系统调用的实现方式中&#xff0c;以调用门和中断门最为适合。由于以后我们将用中断…

自动驾驶纯视觉3D物体检测算法

视频链接&#xff1a;https://www.shenlanxueyuan.com/open/course/112 这是Pseudo-LiDAR作者最近做的一个分享报告&#xff1a;《Pseudo-LiDAR&#xff1a;基于相机的3D物体检测算法》。在这份报告里&#xff0c;作者主要介绍了博士期间的研究成果&#xff1a;基于深度学习的…

一步步编写操作系统 57 门、调用门与RPL序 2

接上文&#xff1a; 提供了4种门的原因是&#xff0c;它们都有各自的应用环境&#xff0c;但它们都是用来实现从低特权级的代码段转向高特权级的代码段&#xff0c;咱们这里也只讨论有关特权级的功用&#xff1a; 1.调用门 call和jmp指令后接调用门选择子为参数&#xff0c;以…

Coursera自动驾驶课程第15讲:GNSS and INS Sensing for Pose Estimation

在上一讲《Coursera自动驾驶课程第14讲&#xff1a;Linear and Nonlinear Kalman Filters》 我们学习了卡尔曼滤波相关知识&#xff0c;包括&#xff1a;线性卡尔曼滤波&#xff08;KF&#xff09;、扩展卡尔曼滤波&#xff08;EKF&#xff09;、误差卡尔曼滤波&#xff08;ES-…

详解车道线检测数据集和模型 VIL-100: A New Dataset and A Baseline Model for Video Instance Lane Detection

本文介绍一个新的车道线数据集 VIL-100 和检测模型 MMA-Net&#xff0c;论文已收录于 ICCV2021&#xff0c;重点是理解本文提出的 LGMA 模块&#xff0c;用于聚合局部和全局记忆特征。 论文链接&#xff1a;https://arxiv.org/abs/2108.08482 项目链接&#xff1a;https://gi…