2018.08.22 hyc的xor/mex(线段树/01trie)

本文介绍了hyc的一道题目,涉及n个数和m个操作的xor/mex问题。每个操作包括对所有数异或x和查询当前数的mex。30%的数据n, m <= 1000,可以用01trie或权值线段树解决,实现思路包括数组模拟和二进制位贪心查询。" 105274548,6677319,Yolov3标注文件转Dlib格式,"['计算机视觉', '深度学习', '图像处理', 'Python编程', '数据标注']

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

hyc的xor/mex
描述

NOIP2017就要来了,备战太累,不如做做hyc的新题?
找回自信吧!
一句话题意:n个数,m个操作
操作具体来讲分两步
1.读入x,把n个数全部xor上x
2.询问当前n个数的mex
意味着每次操作后你都需要输出一次
(注意:是mex,即集合内未出现过的最小非负整数
举2个例子 mex(4,33,0,1,1,5)=2 mex(1,2,3)=0)

输入

第一行两个整数n,m 意义同题面(1 ≤ n, m ≤ 3 * 10^5)
第二行 n个数 ai (0 ≤ ai ≤ 3 * 10^5)
接下来 m 行
每行一个整数 x
表示将所有数xor上x (0 ≤ x ≤ 3 * 10^5).

输出

一共m行
每行表示当前n个数的xor

样例输入

5 4
0 1 5 6 7
1
1
4
5

样例输出

2
2
0
2

提示

30%数据n,m<=1000
100%数据同“输入”

标签

mogician原创

假想有一个01trie,立刻想到对所有数进行异或操作就相当于对有1的二进制位层上的所有节点进行reverse操作,然而这个东西是可以用数组模拟的,于是就只差查询操作了,这个东西直接二进制位贪心查一查就行了。

于是我也分不清楚我写的是01trie还是权值线段树了。
代码:

#include<bits/stdc++.h>
#define N 300005
#define lc (p<<1)
#define rc (p<<1|1)
#define mid (T[p].l+T[p].r>>1)
#define inf ((1<<19)-1)
using namespace std;
inline int read(){
    int ans=0;
    char ch=getchar();
    while(!isdigit(ch))ch=getchar();
    while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
    return ans;
}
inline void write(int x){
    if(x>9)write(x/10);
    putchar(x%10^48);
}
int n,m,s[20];
struct Node{int l,r,cnt;}T[N<<2];
inline void pushup(int p){T[p].cnt=T[lc].cnt+T[rc].cnt;}
inline void build(int p,int l,int r){
    T[p].l=l,T[p].r=r;
    if(l==r){T[p].cnt=0;return;}
    build(lc,l,mid),build(rc,mid+1,r);
}
inline void update(int p,int k){
    if(T[p].l==T[p].r){T[p].cnt=1;return;}
    update(p<<1|(k>mid),k),pushup(p);
}
inline int query(int p,int dep){
    if(T[p].l==T[p].r)return 0;
    int tmp=p<<1|s[dep];
    if(T[tmp].cnt==T[tmp].r-T[tmp].l+1)return query(tmp^1,dep-1)+(1<<dep);
    return query(tmp,dep-1);
}
int main(){
    n=read(),m=read();
    build(1,0,inf);
    while(n--)update(1,read());
    while(m--){
        int x=read();
        for(int j=1;j<=19;++j)if(x&(1<<j))s[j]^=1;
        write(query(1,18)),putchar('\n');
    }
    return 0;
}
hyc@hyc-virtual-machine:~/VINS-Mono/catkin_ws$ roslaunch vins_estimator euroc.launch ... logging to /home/hyc/.ros/log/9d416948-0320-11f0-876f-3d8b158e04bd/roslaunch-hyc-virtual-machine-98811.log Checking log directory for disk usage. This may take a while. Press Ctrl-C to interrupt Done checking log file disk usage. Usage is <1GB. started roslaunch server http://hyc-virtual-machine:46499/ SUMMARY ======== PARAMETERS * /feature_tracker/config_file: /home/hyc/VINS-Mo... * /feature_tracker/vins_folder: /home/hyc/VINS-Mo... * /pose_graph/config_file: /home/hyc/VINS-Mo... * /pose_graph/skip_cnt: 0 * /pose_graph/skip_dis: 0.0 * /pose_graph/visualization_shift_x: 0 * /pose_graph/visualization_shift_y: 0 * /rosdistro: noetic * /rosversion: 1.17.0 * /vins_estimator/config_file: /home/hyc/VINS-Mo... * /vins_estimator/vins_folder: /home/hyc/VINS-Mo... NODES / feature_tracker (feature_tracker/feature_tracker) pose_graph (pose_graph/pose_graph) vins_estimator (vins_estimator/vins_estimator) ROS_MASTER_URI=http://localhost:11311 process[feature_tracker-1]: started with pid [98825] process[vins_estimator-2]: started with pid [98826] process[pose_graph-3]: started with pid [98827] [ INFO] [1742210553.724305322]: init begins [ INFO] [1742210553.732985814]: Loaded config_file: /home/hyc/VINS-Mono/catkin_ws/src/VINS-Mono-master/feature_tracker/../config/euroc/euroc_config.yaml result path /home/shaozu/output//vins_result_no_loop.csv /home/shaozu/output/ not exists, trying to create it /home/shaozu not exists, trying to create it Failed to create folder /home/shaozu [ INFO] [1742210553.733791949]: ROW: 480.000000 COL: 752.000000 [ WARN] [1742210553.733827892]: fix extrinsic param [ INFO] [1742210553.733909885]: Extrinsic_R : 0.0148655 -0.999881 0.0041403 0.999557 0.0149672 0.0257155 -0.0257744 0.00375619 0.999661 [ INFO] [1742210553.733948051]: Extrinsic_T : -0.0216401 -0.064677 0.00981073 [ INFO] [1742210553.733981269]: Synchronized s
03-18
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值