zoukankan      html  css  js  c++  java
  • bzoj 4260: Codechef REBXOR 01trie

      

    类似单调栈维护一个左边的最大值和一个右边的最大值即可

    #include<bits/stdc++.h>
    using namespace std;
    #define rep(i,a,b) for(int i=(a);i<=(b);i++)
    #define repp(i,a,b) for(int i=(a);i>=(b);--i)
    #define ll long long
    #define see(x) (cerr<<(#x)<<'='<<(x)<<endl)
    #define inf 0x3f3f3f3f
    #define CLR(A,v)  memset(A,v,sizeof A)
    //////////////////////////////////
    const int N=4e5+10;
    int t[N<<5][2],ncnt,root;
    void upnode(int x,int rt)
    {
        for(int i=(1<<30);i;i>>=1)
        {
            bool c=i&x;
            if(!t[rt][c])t[rt][c]=++ncnt;
            rt=t[rt][c];
        }
    }
    int qmax(int x,int rt)
    {
        int ans=0;
        for(int i=(1<<30);i;i>>=1)
        {
            bool c=i&x;
            if(t[rt][c^1])ans+=i,rt=t[rt][c^1];
            else if(!t[rt][c])return ans;
            else  rt=t[rt][c];
        }
        return ans;
    }
    int n,m,ans,a[N],s[N],lmax[N],rmax[N];
    int main()
    {
        scanf("%d",&n);
        rep(i,1,n)
        scanf("%d",&a[i]),s[i]=s[i-1]^a[i];
        upnode(0,root);
        rep(i,1,n)
        {
            lmax[i]=max(lmax[i-1],qmax(s[i],root));
            upnode(s[i],root);
        }
        CLR(t,0);
        upnode(0,root);
        repp(i,n,1)s[i]=s[i+1]^a[i];
        repp(i,n,1)
        {
            rmax[i]=max(rmax[i+1],qmax(s[i],root));
            upnode(s[i],root);
        }
        rep(i,1,n)
        ans=max(ans,lmax[i]+rmax[i+1]);
        cout<<ans;
        return 0;
    }
    View Code
  • 相关阅读:
    Swoole 学习笔记 03
    MySQL 索引概念
    MySQL使用存储过程创建百万级别测试数据
    MySQL 慢日志查询的设置
    Hyper中的 Request和Response
    PHPStorm deployment 工具的使用
    Hyperf 命令行
    Hyperf 事件机制
    Hyperf jsonrpc 服务的搭建
    PHPstorm的使用
  • 原文地址:https://www.cnblogs.com/bxd123/p/11518578.html
Copyright © 2011-2022 走看看