社区讨论
求助 0 pts
P5283[十二省联考 2019] 异或粽子参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @m065e01d
- 此快照首次捕获于
- 2024/08/23 11:24 2 年前
- 此快照最后确认于
- 2024/08/23 14:17 2 年前
CPP
#include<bits/stdc++.h>
using namespace std;
#define L(i,j,k) for(int i=j;i<=k;i++)
#define ll long long
const int N=2e7+1000;
int n,k;
ll number[N];
int t[N];
int ch[N][2];
int siz[N],tot;
void insert(ll x){
int u=0;
for(ll i=31;i>=0;i--){
int op=(x>>i)&1;
siz[u]++;
if(!ch[u][op])ch[u][op]=++tot;
u=ch[u][op];
}
siz[u]++;
}
ll query(ll x,int rk){
int u=0;ll ans=0;
for(int i=31;i>=0;i--){
int op=(x>>i)&1;
if(!ch[u][op^1])u=ch[u][op];
else if(rk<=siz[ch[u][op^1]])u=ch[u][op^1],ans|=(1ll<<i);
else rk-=siz[ch[u][op^1]],u=ch[u][op];
}
return ans;
}
#define mp make_pair
#define pr pair<ll,int>
priority_queue< pr > Queue;
ll ans;
int main(){
#ifndef ONLINE_JUDGE
freopen("in.in","r",stdin);
#endif
// ios::sync_with_stdio(0);
cin>>n>>k;k*=2;
L(i,1,n){
cin>>number[i];
number[i]^=number[i-1];
}
L(i,0,n)t[i]=1;
L(i,0,n)insert(number[i]);
L(i,0,n)Queue.push(mp(query(number[i],1),i));
L(i,1,k){
auto x=Queue.top();ans+=x.first;Queue.pop();
if(t[x.second]<n){
t[x.second]++;
Queue.push(mp(query(number[i],t[x.second]),x.second));
}
}
cout<<ans/2<<'\n';
return 0;
}
回复
共 0 条回复,欢迎继续交流。
正在加载回复...