Problem p03215 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932; // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

bool unused[252525];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  vector<ll> sum(n + 1, 0);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    sum[i + 1] = sum[i] + a[i];
  }
  vector<ll> val;
  for (int i = 0; i < n; ++i) {
    for (int j = 1; j <= n - i; ++j) {
      val.push_back(sum[i + j] - sum[i]);
    }
  }
  ll ans = 0;
  int sz = val.size();
  for (int d = 40; d >= 0; --d) {
    int cnt = 0;
    for (int i = 0; i < sz; ++i) {
      if (unused[i])
        continue;
      if ((val[i] >> d) & 1)
        ++cnt;
    }

    if (cnt < k)
      continue;
    ans += (1ll << d);
    for (int i = 0; i < sz; ++i) {
      if (unused[i])
        continue;
      if ((val[i] >> d) & 1)
        continue;
      unused[i] = true;
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932; // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

bool unused[2525252];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  vector<ll> sum(n + 1, 0);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    sum[i + 1] = sum[i] + a[i];
  }
  vector<ll> val;
  for (int i = 0; i < n; ++i) {
    for (int j = 1; j <= n - i; ++j) {
      val.push_back(sum[i + j] - sum[i]);
    }
  }
  ll ans = 0;
  int sz = val.size();
  for (int d = 40; d >= 0; --d) {
    int cnt = 0;
    for (int i = 0; i < sz; ++i) {
      if (unused[i])
        continue;
      if ((val[i] >> d) & 1)
        ++cnt;
    }

    if (cnt < k)
      continue;
    ans += (1ll << d);
    for (int i = 0; i < sz; ++i) {
      if (unused[i])
        continue;
      if ((val[i] >> d) & 1)
        continue;
      unused[i] = true;
    }
  }
  cout << ans << endl;
}