比赛 收心赛 评测结果 AAAAAAAAMMMMAAAAMMMM
题目名称 异或粽子 最终得分 60
用户昵称 LikableP 运行时间 11.794 s
代码语言 C++ 内存使用 417.36 MiB
提交时间 2026-02-24 10:48:43
显示代码纯文本
#include <cstdio>
#include <cctype>

struct IO {
  static const int BUFSIZE = 1 << 20;
  char buf[BUFSIZE], *p1, *p2;
  char pbuf[BUFSIZE], *pp;
  
  IO() : p1(buf), p2(buf), pp(pbuf) {}
  ~IO() { fwrite(pbuf, 1, pp - pbuf, stdout); }
  
  char getchar() {
    if (p1 == p2) {
      p2 = (p1 = buf) + fread(buf, 1, BUFSIZE, stdin);
      if (p1 == p2) return EOF;
    }
    return *p1++;
  }
  
  void putchar(char ch) {
    if (pp - pbuf == BUFSIZE) fwrite(pbuf, 1, BUFSIZE, stdout), pp = pbuf;
    *pp++ = ch;
  }
  
  template <typename T> T read() {
    T res = 0, f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) res = (res << 3) + (res << 1) + (ch ^ 48);
    return res * f;
  }
  
  template <typename T> void write(T x, char ed = '\n') {
    if (x < 0) x = -x, putchar('-');
    static int sta[sizeof(T) << 2], top = 0;
    do {
      sta[++top] = x % 10;
      x /= 10;
    } while (x);
    while (top) {
      putchar(sta[top--] ^ 48);
    }
    putchar(ed);
  }
} io;

#include <vector>
#include <algorithm>
#include <numeric>
typedef long long ll;

const int MAXN = 5e5 + 10;

int n, k;
ll a[MAXN];

int main() {
  #ifdef LOCAL
    freopen("!input.in", "r", stdin);
    freopen("!output.out", "w", stdout);
  #else
    freopen("xor.in", "r", stdin);
    freopen("xor.out", "w", stdout);
  #endif
  
  n = io.read<int>(), k = io.read<int>();
  for (int i = 1; i <= n; ++i) {
    a[i] = io.read<ll>();
    a[i] ^= a[i - 1];
  }
  
  std::vector<ll> v;
  for (int l = 1; l <= n; ++l) {
    for (int r = l; r <= n; ++r) {
      v.push_back(a[l - 1] ^ a[r]);
    }
  }
  
  std::sort(v.begin(), v.end(), [](ll x, ll y) { return x > y; });
  io.write(std::accumulate(v.begin(), v.begin() + k, 0LL));
  return 0;
}