zoukankan      html  css  js  c++  java
  • 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
    ",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;
    }
    
  • 相关阅读:
    Linux监控和安全运维 2.0 zabbix配置邮件告警
    Linux监控和安全运维 1.9 zabbix增加客户端监控
    linux系统构架
    给虚拟机添加eth1网络适配器(网卡)
    linux系统构架
    linux系统构架
    Linux系统构架
    VIM-Sed常用的一些记录。。。逐渐学习。。
    AIX用chsec命令修改快捷修改配置文件
    SYSLOG审记日志的配置。
  • 原文地址:https://www.cnblogs.com/SovietPower/p/10756956.html
Copyright © 2011-2022 走看看