1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| #include<algorithm> #include<iostream> #include<iomanip> #include<cstring> #include<cstdlib> #include<vector> #include<cstdio> #include<cmath> #include<queue> using namespace std; inline const int Get_Int() { int num=0,bj=1; char x=getchar(); while(x<'0'||x>'9') { if(x=='-')bj=-1; x=getchar(); } while(x>='0'&&x<='9') { num=num*10+x-'0'; x=getchar(); } return num*bj; } const int maxn=100005; int n,m,sum1[maxn],sum2[maxn],ans=0,ans2=0; struct Trie { int root,cnt,ch[maxn*25][2]; Trie() { cnt=0; root=++cnt; } void insert(int x) { int now=root; for(int i=n-1; i>=0; i--) { int v=(x>>i)&1; if(!ch[now][v])ch[now][v]=++cnt; now=ch[now][v]; } } void dfs(int now,int depth,int sum) { if(depth<0) { if(sum==ans)ans2++; else if(sum>ans) { ans=sum; ans2=1; } return; } if(ch[now][0]&&ch[now][1]) { dfs(ch[now][0],depth-1,sum); dfs(ch[now][1],depth-1,sum); } else if(ch[now][0])dfs(ch[now][0],depth-1,sum^(1<<depth)); else if(ch[now][1])dfs(ch[now][1],depth-1,sum^(1<<depth)); } } trie; int main() { n=Get_Int(); m=Get_Int(); for(int i=1; i<=m; i++) { int x=Get_Int(); sum1[i]=sum1[i-1]^x; sum2[i]=sum2[i-1]^(((x>>(n-1))+(x<<1))%(1<<n)); } for(int i=0; i<=m; i++)trie.insert(sum2[i]^sum1[m]^sum1[i]); trie.dfs(1,n-1,0); printf("%d\n%d\n",ans,ans2); return 0; }
|