• [Codechef] REBXOR


    [题目链接]

            https://www.lydsy.com/JudgeOnline/problem.php?id=4260

    [算法]

           字典树

           时间复杂度 : O(NlogN)

    [代码]

            

    #include<bits/stdc++.h>
    using namespace std;
    const int MAXN = 4e5 + 10;
    
    int n,ans;
    int a[MAXN],sufmx[MAXN],premx[MAXN],pre[MAXN],suf[MAXN];
    
    template <typename T> inline void read(T &x)
    {
        T f = 1; x = 0;
        char c = getchar();
        for (; !isdigit(c); c = getchar()) if (c == '-') f = -f; 
        for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
        x *= f;
    }
    struct Trie
    {
            int tot;
            int child[MAXN * 31][2];
            inline void clear()
            {
                    tot = 0;
                    memset(child,0,sizeof(child));
            }
            inline void insert(int x)
            {
                    int now = 0;
                    for (int i = 0; i < 31; i++)
                    {
                            int tmp;
                            if (x & (1 << (30 - i))) tmp = 1;
                            else tmp = 0;
                            if (!child[now][tmp]) child[now][tmp] = ++tot;
                            now = child[now][tmp];
                    }
            }
            inline int query(int x)
            {
                    int now = 0 , ret = 0;
                    for (int i = 0; i < 31; i++)
                    {
                            int tmp;
                            if (x & (1 << (30 - i))) tmp = 1;
                            else tmp = 0;
                            if (child[now][tmp ^ 1]) 
                            {
                                    ret += 1 << (30 - i);
                                    now = child[now][tmp ^ 1];
                            } else now = child[now][tmp];
                    }
                    return ret;
            }
    } T;
    
    int main() 
    {
            
            read(n);
            for (int i = 1; i <= n; i++) read(a[i]);
            T.clear();
            T.insert(0);
            for (int i = 1; i <= n; i++)
            {
                    pre[i] = pre[i - 1] ^ a[i];
                    premx[i] = T.query(pre[i]);
                    T.insert(pre[i]);
            }
            for (int i = 1; i <= n; i++) premx[i] = max(premx[i - 1],premx[i]);
            T.clear();
            T.insert(0);
            for (int i = n; i >= 1; i--)
            {
                    suf[i] = suf[i + 1] ^ a[i];
                    sufmx[i] = T.query(suf[i]);
                    T.insert(suf[i]);
            }
            for (int i = n; i >= 1; i--) sufmx[i] = max(sufmx[i],sufmx[i + 1]);
            for (int i = 1; i <= n; i++) ans = max(ans,premx[i] + sufmx[i + 1]);
            printf("%d
    ",ans);
            
            return 0;
        
    }
  • 相关阅读:
    保存ADO的记录集为XML文件
    [C++] Undefined reference to vtable
    Csdn博客的一个bug
    深入解析ATL(第二版ATL8.0)(1.111.13节)
    不同操作系统下记事本的换行符号
    dom4j学习总结(一)
    关于firefox的copy/paste的问题
    php URL编码解码函数
    php连接MySQL数据库的一些问题
    使用 jQuery progressBar 做文件上传的进度条指示
  • 原文地址:https://www.cnblogs.com/evenbao/p/9610743.html
Copyright © 2020-2023  润新知