[蓝桥杯] 异或和之差

文章介绍了如何利用01trie数据结构在给定数组的异或前缀和基础上找到最大和最小异或对,通过维护四个数组lmax、lmin、rmax和rmin来实现高效查询。

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

题目描述:
https://www.lanqiao.cn/problems/3524/learning/
思路: : 01trie求最大(最小)异或对 。 先看一边, 我们对数组进行一次异或前缀和,得到异或前缀数组b[N], 从b中选两个数,相当于取一段区间,这就可以使用01trie去找最大(最小)异或对了。使用4个数组lmax[N], lmin[N],rmax[N],rmin[N]分别去记录1 – N位置和N – 1位置的最大异或值和最小异或值。最后对每个位置去做一次max - min 即可。

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
//#define int long long
#define ios ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
const int N = 2e5+5;
int a[N], b[N], b1[N], lch[N*21][2],rch[N*21][2], lidx, ridx, n;
int lmax[N], rmax[N], lmin[N], rmin[N];
void insert(int x, int ch[][2], int &idx){
   
    int p = 0;
    for(
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值