第二个数据点到底是什么?

P4735 最大异或和

```cpp #include<iostream> #include<cstdlib> #include<cstdio> #include<cmath> #include<algorithm> #include<cstring> #define rg register #define _ 600001 using namespace std; int n,a[_],num,root[_],ans,m; struct pp { int son[2],cnt; }trie[_*30]; inline int read() { rg int save=0,w=1;rg char q=getchar(); while(q<'0'||q>'9'){if(q=='-')w=-1;q=getchar();} while(q>='0'&&q<='9')save=(save<<3)+(save<<1)+q-'0',q=getchar(); return save*w; } void build(int &i,int x,int ceng)//ceng:第几层 { trie[++num]=trie[i]; i=num; trie[i].cnt++; if(ceng<0)return; bool b=(x&(1<<ceng)); build(trie[i].son[b],x,ceng-1); } void ask(int l,int r,int x,int ceng) { if(ceng<0)return; bool b=(x&(1<<ceng)); int ought1=trie[l].son[!b],ought2=trie[r].son[!b]; int wrong1=trie[l].son[b],wrong2=trie[r].son[b]; if(trie[ought2].cnt-trie[ought1].cnt>0) ans+=(1<<ceng),ask(ought1,ought2,x,ceng-1); else if(trie[wrong2].cnt-trie[wrong1].cnt>0)ask(wrong1,wrong2,x,ceng-1); } int main() { n=read()+1,m=read(); rg int i,j; for(i=2;i<=n;++i) { a[i]=read(); a[i]^=a[i-1]; root[i]=root[i-1]; build(root[i],a[i],24); } for(i=1;i<=m;++i) { // 游荡的孤高灵魂不需要羁绊之地! char q=getchar(); while(q!='A'&&q!='Q')q=getchar(); if(q=='A') { a[++n]=read(); a[n]^=a[n-1]; root[n]=root[n-1]; build(root[n],a[n],24); } else { ans=0; int l=read(),r=read(),x=read();x^=a[n]; ask(root[l-1],root[r],x,24); printf("%d\n",ans); } } return 0; } ```
by 天依赛高! @ 2018-08-15 15:15:12


现在解决啦 测试点里v=1,即询问1异或到n再异或x的值,我的代码没处理root[0/1]的树,所以挂了
by 天依赛高! @ 2018-08-15 15:35:41


|