D1T1:异或粽子
显然令b[]为a[]的前缀和,那么就是在b[]中任取两数异或,求异或结果前k大和。
于是暴力$O(n^2)$显然,60pts。
1 #include<cstdio> 2 #include<algorithm> 3 #define rep(i,l,r) for (int i=(l); i<=(r); i++) 4 typedef long long ll; 5 using namespace std; 6 7 const int N=2000010; 8 int n,k,tot; 9 ll ans,a[N],b[N],s[N]; 10 11 int main(){ 12 freopen("xor.in","r",stdin); 13 freopen("xor.out","w",stdout); 14 scanf("%d%d",&n,&k); 15 rep(i,1,n) scanf("%lld",&a[i]),b[i]=b[i-1]^a[i]; 16 rep(i,1,n) rep(j,0,i-1) s[++tot]=b[i]^b[j]; 17 sort(s+1,s+tot+1); 18 for (int i=tot; i>=tot-k+1; i--) ans+=s[i]; 19 printf("%lld\n",ans); 20 return 0; 21 }