BZOJ.4184.shallot(线段树分治 线性基)

BZOJ


裸的线段树分治+线性基,就是跑的巨慢_(:з」∠)_ 。
不知道他们都写的什么=-=


//41652kb   11920ms
#include <map>
#include <cstdio>
#include <cctype>
#include <vector>
#include <algorithm>
#define BIT 30
#define gc() getchar()
#define MAXIN 500000
//#define gc() (SS==TT&&(TT=(SS=IN)+fread(IN,1,MAXIN,stdin),SS==TT)?EOF:*SS++)
typedef long long LL;
const int N=5e5+5;

std::map<int,int> las;
char IN[MAXIN],*SS=IN,*TT=IN;
struct Base
{
    int x[BIT+1];
    void Insert(int v)
    {
        for(int i=BIT; ~i; --i)
            if(v>>i&1)
                if(x[i]) v^=x[i];
                else {x[i]=v; break;}
    }
    void Query()
    {
        int res=0;
        for(int i=BIT; ~i; --i) res=std::max(res,res^x[i]);
        printf("%d\n",res);
    }
}base;
struct Segment_Tree
{
    #define ls rt<<1
    #define rs rt<<1|1
    #define lson l,m,ls
    #define rson m+1,r,rs
    #define S N<<2
    std::vector<int> vec[S];
    #undef S
    void Modify(int l,int r,int rt,int L,int R,int v)
    {
        if(L<=l && r<=R) {vec[rt].push_back(v); return;}
        int m=l+r>>1;
        if(L<=m) Modify(lson,L,R,v);
        if(m<R) Modify(rson,L,R,v);
    }
    void Solve(int l,int r,int rt,Base b)
    {
        for(std::vector<int>::iterator it=vec[rt].begin(); it!=vec[rt].end(); ++it) b.Insert(*it);
        if(l==r) {b.Query(); return;}
        int m=l+r>>1; Solve(lson,b), Solve(rson,b);
    }
}T;

inline int read()
{
    int now=0;register char c=gc();
    for(;!isdigit(c);c=gc());
    for(;isdigit(c);now=now*10+c-48,c=gc());
    return now;
}

int main()
{
    #define S 1,n,1
    const int n=read();
    for(int i=1; i<=n; ++i)
    {
        int a=read();
        if(las[a]) T.Modify(S,las[a],i-1,a), las[a]=0;
        else las[a]=i;
    }
    for(std::map<int,int>::iterator it=las.begin(); it!=las.end(); ++it)
        if((*it).second) T.Modify(S,(*it).second,n,(*it).first);
    T.Solve(S,base);

    return 0;
}

转载于:https://www.cnblogs.com/SovietPower/p/10756956.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值