给定一个非负整数序列 {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 最大,输出最大是多少。
标签:
可持久化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\n",query(root[u-1],root[v],temp^d,24));
}
return 0;
}
给定一个非负整数序列 {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 最大,输出最大是多少。
第一行包含两个整数 N ,M,含义如问题描述所示。
第二行包含 N个非负整数,表示初始的序列 A 。
接下来 M行,每行描述一个操作,格式如题面所述。
假设询问操作有 T个,则输出应该有 T行,每行一个整数表示询问的答案。
对于 100% 的数据, 0<=a[i]<=10^7 。
标签:
原文地址:http://www.cnblogs.com/fighting-to-the-end/p/5714924.html