比赛 收心赛 评测结果 AAAAAAAAEEEEAAAAEEEE
题目名称 异或粽子 最终得分 60
用户昵称 KKZH 运行时间 2.700 s
代码语言 C++ 内存使用 10.43 MiB
提交时间 2026-02-24 10:56:08
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=5e5+10;
int n,k,ans;
int a[N],xr[N],tot[N],cnt;
bool cmp(int a,int b){
    return a>b; 
}
signed main(){
	freopen("xor.in","r",stdin);
	freopen("xor.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        xr[i]=a[i]^xr[i-1];
//        cout<<xr[i]<<" ";
    }
    for(int i=1;i<=n;i++){
        for(int j=i;j<=n;j++){
            tot[++cnt]=xr[j]^xr[i-1];
        }
    }
//    cout<<(3^0);
    sort(tot+1,tot+1+cnt,cmp);
    for(int i=1;i<=k;i++){
        ans+=tot[i];
//        cout<<tot[i]<<endl;
    }
    cout<<ans;
    return 0;
}