1 条题解

  • 0
    @ 2022-11-10 21:06:23
    #include<algorithm>
    #include<cstring>
    #include<vector>
    using namespace std;
    const int N=4e5+10;
    int son[N*30][2],idx;
    int a[N];
    int sum[N];
    int l[N],r[N];
    void insert(int x)
    {
        int p = 0;
        for(int i = 30; i >= 0; i--)
        {
            int u = (x >> i) & 1;
            if(!son[p][u]) 
    			son[p][u] = ++idx;
            p = son[p][u];
        }
    }
    int query(int x)
    {
        int res = 0;
        for(int p = 0, i = 30; i >= 0; i--)
        {
            int u = (x >> i) & 1;
            if(son[p][!u])
            {
                res = res * 2 + 1;
                p = son[p][!u];
            }
    		else
            {
                res = res * 2;
                p = son[p][u];
            }
        }
        return res;
    }
    int main()
    {
        int n;
        scanf("%d", &n);
        
        for(int i = 1; i <= n; i++)
        	scanf("%d", &a[i]);
        	
        for(int i = 1; i <= n; i++)
            sum[i] = sum[i-1] ^ a[i];
        
        int lm = 0 , rm = 0;
        
        for(int i = 1; i <= n; i++)
        {
            int t = query(sum[i]);
            insert(sum[i]);
            if(t >= lm)
            {
                lm = t;
                rm = lm;
            }
    		else if(t < lm && t > rm)
            {
                rm = t;
            }
        }
        cout<<lm + rm;
            return 0;
    } 
    
    
    • 1

    信息

    ID
    392
    时间
    1000ms
    内存
    512MiB
    难度
    10
    标签
    递交数
    6
    已通过
    1
    上传者