0pts 求调
#include<bits/stdc++.h>
#define N 1000005
#define int long long
using namespace std;
int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n,m,a[N],tot,late[N*20],awa,tr[N*20][2],size[N*2],rt[N],ans;
int news(int now)
{
int to=++tot;
tr[to][0]=tr[now][0];
tr[to][1]=tr[now][1];
size[to]=size[now];
return to;
}
int insert(int now,int x,int dep)
{
int to=news(now);
if(dep==0)
{
late[to]=awa;
return to;
}
bool c=((x>>(dep-1))&1);
tr[to][c]=insert(tr[now][c],x,dep-1);
size[tr[to][c]]++;
return to;
}
int que(int l,int r,int x,int dep)
{
if(dep==0)return late[r];
bool c=!((x>>(dep-1))&1);
if(size[tr[r][c]]>size[tr[l][c]])return que(tr[l][c],tr[r][c],x,dep-1);
return que(tr[l][!c],tr[r][!c],x,dep-1);
}
struct node
{
int i,l,r,ans,x;
bool operator<(node a)const{return ans<a.ans;}
};
priority_queue<node> q;
void out(node now)
{
cout<<now.i<<" "<<now.l<<" "<<now.r<<" "<<now.ans<<" "<<now.x<<"|\n";
}
signed main()
{
n=read();m=read();
rt[0]=insert(0,0,30);
for(int i=1;i<=n;i++)
{
a[i]=(read()^a[i-1]);awa=i;
rt[i]=insert(rt[i-1],a[i],30);
int u=que(0,rt[i],a[i],30);
q.push(node{i,0,i,(a[u]^a[i]),u});
}
int cnt=0;node now;
while(cnt<m)
{
now=q.top();q.pop();
ans+=now.ans;cnt++;
if(now.x!=now.l)
{
int u=que(rt[now.l-1],rt[now.x-1],a[now.i],30);
q.push(node{now.i,now.l,now.x-1,(a[u]^a[now.i]),u});
}
if(now.x!=now.r)
{
int u=que(rt[now.x],rt[now.r],a[now.i],30);
q.push(node{now.i,now.x+1,now.r,(a[u]^a[now.i]),u});
}
}
cout<<ans<<"\n";
return 0;
}