题目描述:
思路: : 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(