• bzoj3261: 最大异或和


    可持久化trie。又是%%%Xs酱。。。

    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    #define REP(i,s,t) for(int i=s;i<=t;i++)
    #define dwn(i,s,t) for(int i=s;i>=t;i--)
    #define clr(x,c) memset(x,c,sizeof(x))
    int read(){
        int x=0;char c=getchar();bool f=true;
        while(!isdigit(c)){
            if(c=='-') f=false;c=getchar();
        }
        while(isdigit(c)) x=x*10+c-'0',c=getchar();
        return f?x:-x;
    } 
    const int nmax=600005;
    struct node{
        int cnt,son[2];
    };
    node nodes[20000000];
    int root[nmax],pt=0;
    void insert(int p,int &q,int x,int cur){
        q=++pt;nodes[q].cnt=nodes[p].cnt+1;
        if(cur<0) return ;
        int tmp=(x>>cur)&1;
        nodes[q].son[tmp^1]=nodes[p].son[tmp^1];
        insert(nodes[p].son[tmp],nodes[q].son[tmp],x,cur-1);
    }
    int query(int p,int q,int x,int cur){
        if(cur<0) return 0;
        int tmp=(x>>cur)&1;
        if(nodes[nodes[p].son[tmp^1]].cnt==nodes[nodes[q].son[tmp^1]].cnt) 
          return query(nodes[p].son[tmp],nodes[q].son[tmp],x,cur-1);
        else return query(nodes[p].son[tmp^1],nodes[q].son[tmp^1],x,cur-1)+(1<<cur);
    }
    char s[5];
    int main(){
        int n=read(),m=read(),u,v,d,temp=0;
        root[0]=0,nodes[0].cnt=nodes[0].son[0]=nodes[0].son[1]=0;
        insert(root[0],root[1],0,24);
        REP(i,1,n) u=read(),temp^=u,insert(root[i],root[i+1],temp,24);
        n++;
        REP(i,1,m){
            scanf("%s",s);
            if(s[0]=='A') u=read(),temp^=u,n++,insert(root[n-1],root[n],temp,24);
            else u=read(),v=read(),d=read(),printf("%d
    ",query(root[u-1],root[v],temp^d,24));
        }
        return 0;
    }
    

      

    3261: 最大异或和

    Time Limit: 10 Sec  Memory Limit: 512 MB
    Submit: 1318  Solved: 553
    [Submit][Status][Discuss]

    Description

         

    给定一个非负整数序列 {a},初始长度为 N。       
    有   M个操作,有以下两种操作类型:
     
    1 、A x:添加操作,表示在序列末尾添加一个数 x,序列的长度 N+1。
    2 、Q l r x:询问操作,你需要找到一个位置 p,满足 l<=p<=r,使得:
     
    a[p] xor a[p+1] xor ... xor a[N] xor x 最大,输出最大是多少。  

    Input

    第一行包含两个整数 N  ,M,含义如问题描述所示。   
    第二行包含 N个非负整数,表示初始的序列 A 。 
     
    接下来 M行,每行描述一个操作,格式如题面所述。   

    Output

    假设询问操作有 T个,则输出应该有 T行,每行一个整数表示询问的答案。

    Sample Input

    5 5
    2 6 4 3 6
    A 1
    Q 3 5 4
    A 4
    Q 5 7 0
    Q 3 6 6
    对于测试点 1-2,N,M<=5 。

    对于测试点 3-7,N,M<=80000 。
    对于测试点 8-10,N,M<=300000 。

    其中测试点 1, 3, 5, 7, 9保证没有修改操作。
    对于 100% 的数据, 0<=a[i]<=10^7。

    Sample Output

    4
    5
    6

    HINT

    对于      100%  的数据,     0<=a[i]<=10^7  。

    Source

     
    [Submit][Status][Discuss]
  • 相关阅读:
    挑战程序设计竞赛 第2章习题 poj 1017 Packets 贪心模拟
    挑战程序设计竞赛 2章习题 poj 2376 Cleaning Shifts
    Leetcode 27. 移除元素 双指针
    Leetcode 26. 删除有序数组中的重复项 双指针
    Leetcode 31. 下一个排列
    webserver 发布问题
    [转]机器学习中的各种距离
    VUE3 + TYPESCRIPT 开发实践总结
    我和ABP vNext 的故事
    ABP Framework 为什么好上手,不好深入?探讨最佳学习姿势!
  • 原文地址:https://www.cnblogs.com/fighting-to-the-end/p/5714924.html
Copyright © 2020-2023  润新知