bzoj 4184: shallot (线段树维护线性基)
Posted 812-xiao-wen
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了bzoj 4184: shallot (线段树维护线性基)相关的知识,希望对你有一定的参考价值。
题面
(solution:)
(code:)
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#define ll long long
#define db double
#define inf 0x7fffffff
#define rg register int
#define pb push_back
#define midd int mid=(l+r)>>1
#define klr int k,int l,int r
#define zuo k<<1,l,mid
#define you k<<1|1,mid+1,r
using namespace std;
map<int,int> h;
vector<int> a[500005<<2];
int d[31];
int n,v,sl,sr;
int c[500005];
struct ji{
int b[31];
ji(){memset(b,0,sizeof(0));}
inline void add(int x){
for(rg i=30;i>=0;--i)
if(x&d[i]){
if(b[i])x^=b[i];
else {b[i]=x;return;}
}
}
inline int ask(){
int res=0;
for(rg i=30;i>=0;--i)
if(b[i]&&!(res&d[i]))res^=b[i];
return res;
}
}base;
inline int qr(){
char ch; int sign=1;
while((ch=getchar())<'0'||ch>'9')
if(ch=='-')sign=-1;
int res=ch^48;
while((ch=getchar())>='0'&&ch<='9')
res=res*10+(ch^48);
return res*sign;
}
inline void add(klr){
if(sl<=l&&r<=sr){ a[k].pb(-v); return ;}
midd; if(sl<=mid)add(zuo); if(sr>mid)add(you);
}
inline void dfs(klr,ji t){
for(rg i=0,j=a[k].size();i<j;++i) t.add(a[k][i]);
if(l==r){printf("%d
",t.ask());return ;}
midd; dfs(zuo,t); dfs(you,t);
}
int main(){
freopen("team.in","r",stdin);
freopen("team.out","w",stdout);
n=qr();
for(rg i=30;i>=0;--i)d[i]=1<<i;
for(rg i=1;i<=n;++i){
if((c[i]=v=qr())>=0)h[v]=i;
else sl=h[-v],h[-v]=0,sr=i-1,add(1,1,n);
}
for(rg i=1;i<=n;++i)
if(c[i]>0&&h[c[i]])
sl=h[c[i]],sr=n,v=-c[i],add(1,1,n);
dfs(1,1,n,base);
return 0;
}
以上是关于bzoj 4184: shallot (线段树维护线性基)的主要内容,如果未能解决你的问题,请参考以下文章