# [bzoj4184]shallot(线段树分治,线性基)

Description

Input

Output

Sample Input
6
1 2 3 4 -2 -3
Sample Output
1
3
3
7
7
5
Hint
N<=500000,Ai<=2^31-1

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define mid ((l+r)>>1)
#define lc (rt<<1)
#define rc ((rt<<1)|1)
#define maxn 500005
using namespace std;
int cnt,n,len;
vector<int> seg[maxn<<2];
struct number{int x,l,r;}p[maxn];
struct node
{
int num,base[33];
void insert(int x)
{
if(num==32)return;
for(int i=31;~i;i--)
if(x&(1<<i))
{
if(!base[i]){base[i]=x;++num;}
x^=base[i];
}
}
int getmax(int x){for(int i=31;~i;i--)x=max(x,x^base[i]);return x;}
}A;
void update(int rt,int l,int r,int L,int R,int x)
{
if(l>R||r<L)return;
if(L<=l&&r<=R){seg[rt].push_back(x);return;}
update(lc,l,mid,L,R,x);update(rc,mid+1,r,L,R,x);
}
void divide(int rt,int l,int r,node A)
{
for(int i=seg[rt].size()-1;A.num<32&&~i;i--)A.insert(seg[rt][i]);
for(int i=l;i<=r;i++)ans[i]=max(ans[i],A.getmax(0));
if(l==r)return;divide(lc,l,mid,A);divide(rc,mid+1,r,A);
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)scanf("%d",&seq[i]);
for(int i=1;i<=n;i++)b[i]=abs(seq[i]);
sort(b+1,b+1+n);len=unique(b+1,b+1+n)-b-1;
for(int i=1;i<=n;i++)
{
if(seq[i]>0)
{
int u=lower_bound(b+1,b+1+len,seq[i])-b;
p[cnt]=(number){seq[i],i,n};
}
else
{
int u=lower_bound(b+1,b+1+len,-seq[i])-b;