• bzoj 4260REBXOR


    什么什么trie树??呵呵呵,,,,

    一直在困惑怎么处理哪连续一段最大。。看了题解迷惑了好久。。

    然后突然发现,是xor啊,,在trie树里找到以前得插入的前缀和,然后找到与现在前缀和每一位都不同的,那xor起来就是最大了。。2333(就是乱(差分??(是叫差分来吗??)))

     1 #include<bits/stdc++.h>
     2 #define inf 0x7fffffff
     3 #define LL long long
     4 #define N 100005
     5 using namespace std;
     6 inline int ra()
     7 {
     8     int x=0,f=1; char ch=getchar();
     9     while (ch<'0' || ch>'9') {if (ch=='-') f=-1; ch=getchar();}
    10     while (ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
    11     return x*f;
    12 }
    13 int cnt,ans,child[N<<7][2],a[N<<2],lmax[N<<2],rmax[N<<2];
    14 void build(int x)
    15 {
    16     int now=0;
    17     for (int i=1<<30; i; i>>=1)
    18     {
    19         int w=(x&i)?1:0;
    20         if (!child[now][w]) child[now][w]=++cnt;
    21         now=child[now][w];
    22     }
    23 }
    24 int cal(int x)
    25 {
    26     int now=0,ans=0;
    27     for (int i=1<<30; i; i>>=1)
    28     {
    29         int w=(x&i)?0:1;
    30         if (child[now][w]) ans+=i,now=child[now][w];
    31             else now=child[now][!w];
    32     }
    33     return ans;
    34 }
    35 int main()
    36 {
    37     int n=ra(),now,i;
    38     for (int i=1; i<=n; i++) a[i]=ra();
    39     for (build(now=0), i=1; i<=n; i++)
    40     {
    41         build(now^=a[i]);
    42         lmax[i]=max(lmax[i-1],cal(now));
    43     }
    44     memset(child,0,sizeof(child));
    45     for (build(now=cnt=0), i=n; i>=1; i--)
    46     {
    47         build(now^=a[i]);
    48         rmax[i]=max(rmax[i+1],cal(now));
    49     }
    50     for (int i=0; i<=n; i++)
    51         ans=max(ans,lmax[i]+rmax[i+1]);
    52     cout<<ans;
    53     return 0;
    54 }
  • 相关阅读:
    Linux下的lds链接脚本简介
    Fedora下载地址
    SkyEye的使用
    shell变量详解
    Linux shell 脚本攻略之正则表达式入门
    Linux shell 脚本攻略之统计文件的行数、单词数和字符数
    Linux shell 脚本攻略之创建不可修改文件
    Linux shell 脚本攻略之生成任意大小的文件
    Linux shell 脚本攻略之批量重命名
    Linux shell 脚本攻略之文件查找与文件列表
  • 原文地址:https://www.cnblogs.com/ccd2333/p/6385212.html
Copyright © 2020-2023  润新知