alexjercan/bugnet huggingface dataset:
Problem p01635 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cfloat>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define NUM 1000000000

int main() {

  ull N, T;
  scanf("%llu %llu", &N, &T);

  char buf[100];
  scanf("%s", buf);

  ull sum = 0;

  for (int i = 0; buf[i] != '\\0' && buf[i] == 'n';) {
    ull tmp = N;

    int count = buf[i + 2] - '0';

    if (count == 0) {
      tmp = 1;
    } else {

      for (int k = 0; k < count - 1; k++) {
        if (tmp * N > NUM) {
          printf("TLE\\n");
          return 0;
        }
        tmp *= N;
      }
    }
    sum += tmp;
    if (sum > NUM) {
      printf("TLE\\n");
      return 0;
    }
    i += 4;
  }

  if (sum * T > NUM) {
    printf("TLE\\n");
    return 0;
  } else {
    sum *= T;
  }

  printf("%llu\\n", sum);

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cfloat>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define NUM 1000000000

int main() {

  ull N, T;
  scanf("%llu %llu", &N, &T);

  char buf[100];
  scanf("%s", buf);

  ull sum = 0;

  for (int i = 0; buf[i] != '\\0';) {
    if (buf[i] == 'n') {
      ull tmp = N;

      int count = buf[i + 2] - '0';

      for (int k = 0; k < count - 1; k++) {
        if (tmp * N > NUM) {
          printf("TLE\\n");
          return 0;
        }
        tmp *= N;
      }
      sum += tmp;
      if (sum > NUM) {
        printf("TLE\\n");
        return 0;
      }
      i += 4;
    }
  }

  if (sum * T > NUM) {
    printf("TLE\\n");
    return 0;
  } else {
    sum *= T;
  }

  printf("%llu\\n", sum);

  return 0;
}
Problem p01635 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iostream>
using namespace std;

long long TLE = 1000000000;

long long calc(int n, int T) {
  long long tmp = 1;
  for (int i = 0; i < 10; ++i) {
    if (tmp > TLE)
      return i;
    tmp *= n;
  }

  return 10;
}

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

  long long n, T;
  cin >> n >> T;

  TLE /= T;

  long long limit = calc(n, T);

  string f;
  cin >> f;

  const int len = (int)f.size();

  long long tmp = 0;
  for (int i = 0; i < len; ++i) {
    if (isdigit(f[i])) {
      const int exp = f[i] - '0';
      if (exp >= limit) {
        tmp = TLE + 1;
        break;
      }

      tmp += (long long)pow<double>(n, exp);
      if (tmp > TLE)
        break;
    }
  }

  if (tmp > TLE)
    cout << "TLE" << endl;
  else
    cout << tmp * T << endl;

  return EXIT_SUCCESS;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iostream>
using namespace std;

long long TLE = 1000000000;

long long calc(int n, int T) {
  long long tmp = 1;
  for (int i = 0;; ++i) {
    if (tmp > TLE)
      return i;
    tmp *= n;
  }
}

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

  long long n, T;
  cin >> n >> T;

  TLE /= T;

  long long limit = calc(n, T);

  string f;
  cin >> f;

  const int len = (int)f.size();

  long long tmp = 0;
  for (int i = 0; i < len; ++i) {
    if (isdigit(f[i])) {
      const int exp = f[i] - '0';
      if (exp >= limit) {
        tmp = TLE + 1;
        break;
      }

      tmp += (long long)pow<double>(n, exp);
      if (tmp > TLE)
        break;
    }
  }

  if (tmp > TLE)
    cout << "TLE" << endl;
  else
    cout << tmp * T << endl;

  return EXIT_SUCCESS;
}
Problem p01636 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int toInt(string s) {
  int res = 0;
  for (int i = 0; i < s.size(); i++) {
    res *= 10;
    res += s[i] - '0';
  }
  return res;
}

int main(void) {

  string s;
  cin >> s;

  int cnt = 0, n = toInt(s);
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '0')
      continue;
    int a = toInt(s.substr(0, i));
    int b = toInt(s.substr(i, s.size() - i));
    if (a > b)
      break;
    if ((a + b) % 2 == 0 && (b - a) % 2 == 0)
      cnt++;
  }

  cout << cnt << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int toInt(string s) {
  int res = 0;
  for (int i = 0; i < s.size(); i++) {
    res *= 10;
    res += s[i] - '0';
  }
  return res;
}

int main(void) {

  string s;
  cin >> s;

  int cnt = 0, n = toInt(s);
  for (int i = 1; i < s.size(); i++) {
    if (s[i] == '0')
      continue;
    int a = toInt(s.substr(0, i));
    int b = toInt(s.substr(i, s.size() - i));
    for (int x = 0; x <= 1000000000; x++) {
      if (x + x - a == b)
        cnt++;
      if (x + x == n)
        cnt++;
    }
  }

  cout << cnt << endl;

  return 0;
}
Problem p01637 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define REV(s) (s).rbegin(), (s).rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

ll pay[2][1000];
ll lost[2][1000];
int main() {
  ll m, r[2], c[2];
  cin >> m >> r[0] >> r[1] >> c[0] >> c[1];

  rep(j, 2) rep(i, 1000) pay[j][i] = lost[j][i] = 1ll << 60;

  rep(i, 2) {
    ll Min = 100 * c[i] / r[i];
    for (ll x = Min; x < Min + 1000; x++) {
      ll D = x * r[i] / 100;
      D -= c[i];
      if (D < 0)
        continue;
      ll rest = D * 100 / r[i];
      pay[i][x - Min] = x;
      lost[i][x - Min] = x - rest;
    }
  }

  ll ans = 1ll << 60;
  rep(i, 1000) rep(j, 1000) {
    if (pay[0][i] + pay[1][j] > m)
      continue;
    ans = min(ans, lost[0][i] + lost[1][j]);
  }
  if (m < ans)
    cout << -1 << endl;
  else
    cout << m - ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define REV(s) (s).rbegin(), (s).rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

ll pay[2][1000];
ll lost[2][1000];
int main() {
  ll m, r[2], c[2];
  cin >> m >> r[0] >> r[1] >> c[0] >> c[1];

  rep(j, 2) rep(i, 1000) pay[j][i] = lost[j][i] = 1ll << 60;

  rep(i, 2) {
    ll Min = 100 * c[i] / r[i];
    for (int x = Min; x < Min + 1000; x++) {
      ll D = x * r[i] / 100;
      D -= c[i];
      if (D < 0)
        continue;
      ll rest = D * 100 / r[i];
      pay[i][x - Min] = x;
      lost[i][x - Min] = x - rest;
    }
  }

  ll ans = 1ll << 60;
  rep(i, 1000) rep(j, 1000) {
    if (pay[0][i] + pay[1][j] > m)
      continue;
    ans = min(ans, lost[0][i] + lost[1][j]);
  }
  if (m < ans)
    cout << -1 << endl;
  else
    cout << m - ans << endl;

  return 0;
}
Problem p01637 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
typedef long long int ll;
ll M, rd, rr, cd, cr;

ll exc(ll rate, ll c) {
  if (c == 0)
    return 0;
  ll r = 0, l = 10000000000000000;
  while (l - r > 0) {
    ll m = (r + l) / 2;
    ll y = rate * m / 100;
    ll y1 = rate * (m - 1) / 100;
    if (y == c && y1 != c)
      return m;
    if (y < c) {
      r = m;
    } else {
      l = m;
    }
  }
  return 10000000000000000;
}

int main() {
  cin >> M >> rd >> rr >> cd >> cr;
  ll a = exc(rd, cd);
  ll b = exc(rr, cr);
  ll r = M - a - b;
  if (r < 0) {
    cout << -1 << endl;
    return 0;
  }
  cout << r << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
typedef long long int ll;
ll M, rd, rr, cd, cr;

ll exc(ll rate, ll c) {
  ll x = c;
  while (1) {
    if (x > M)
      return -1;
    ll y = rate * x / 100;
    if (y >= c)
      return x;
    x++;
  }
}

int main() {
  cin >> M >> rd >> rr >> cd >> cr;
  ll a = exc(rd, cd);
  if (a == -1) {
    cout << -1 << endl;
    return 0;
  }
  M -= a;
  ll b = exc(rr, cr);
  if (b == -1) {
    cout << -1 << endl;
    return 0;
  }
  cout << M - b << endl;
  return 0;
}
Problem p01637 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

int main() {

  long long m, rd, rr, cd, cr;

  cin >> m >> rd >> rr >> cd >> cr;

  long long w1 = (100 * cd + rd - 1) / rd;
  long long w2 = (100 * cr + rr - 1) / rr;

  if (m < w1 + w2) {
    cout << -1 << endl;
  } else {
    cout << m - (w1 + w2) << endl;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {

  long long m, rd, rr, cd, cr;
  long long sum_d, sum_r;
  bool k1 = false;
  bool k2 = false;

  cin >> m >> rd >> rr >> cd >> cr;

  for (long long i = cd; i <= m; ++i) {
    if ((rd * i) / 100 >= cd) {
      sum_d = i;
      k1 = true;
      break;
    }
  }

  if (k1 == false) {
    cout << -1 << endl;
    return 0;
  }

  for (long long i = cr; i <= m - sum_d; ++i) {
    if ((rr * i) / 100 >= cr) {
      sum_r = i;
      k2 = true;
      break;
    }
  }

  if (k2 == false) {
    cout << -1 << endl;
    return 0;
  }

  cout << m - sum_d - sum_r << endl;
}
Problem p01639 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

typedef long long Int;
typedef unsigned long long uInt;

int cnt[256000];

int main() {
  int n, k, x0;

  scanf("%d %d %d", &n, &k, &x0);

  if (x0 == 0)
    return (!printf("0\\n"));

  Int width = LLONG_MAX / 100000;
  uInt x = x0;
  for (int i = 0; i < n; i++) {
    cnt[(uInt)((Int)x - LLONG_MIN) / width]++;
    x ^= x << 13;
    x ^= x >> 7;
    x ^= x << 17;
  }

  int sum = 0;
  for (int i = 0; i < 256000; i++) {
    sum += cnt[i];
    if (sum < k)
      continue;
    vector<Int> a;

    x = x0;
    for (int j = 0; j < n; j++) {
      Int xd = (Int)x;
      if ((uInt)((Int)x - LLONG_MIN) / width == i)
        a.push_back(xd);
      x ^= x << 13;
      x ^= x >> 7;
      x ^= x << 17;
    }
    sort(a.begin(), a.end());
    printf("%lld\\n", a[k - (sum - cnt[i]) - 1]);
    return (0);
  }

  return (-1);
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long Int;
typedef unsigned long long uInt;

int main() {
  int n, k, x0 = 1;

  scanf("%d %d %d", &n, &k, &x0);

  int cnt[256000];
  memset(cnt, 0, sizeof(cnt));
  Int width = LLONG_MAX / 100000;
  uInt x = x0;
  for (int i = 0; i < n; i++) {
    cnt[(uInt)((Int)x - LLONG_MIN) / width]++;
    x ^= x << 13;
    x ^= x >> 7;
    x ^= x << 17;
  }

  int sum = 0;
  for (int i = 0; i < 256000; i++) {
    sum += cnt[i];
    if (sum < k)
      continue;
    vector<Int> a;

    x = x0;
    for (int j = 0; j < n; j++) {
      Int xd = (Int)x;
      if ((uInt)((Int)x - LLONG_MIN) / width == i)
        a.push_back(xd);
      x ^= x << 13;
      x ^= x >> 7;
      x ^= x << 17;
    }
    sort(a.begin(), a.end());
    printf("%lld\\n", a[k - (sum - cnt[i]) - 1]);
    return (0);
  }

  return (-1);
}
Problem p01639 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef unsigned long long ull;
int x, n, k, cnt[1050000];
int main() {
  cin >> n >> k >> x;
  k--;
  if (x == 0) {
    cout << 0 << endl;
    return 0;
  }
  ull z1 = x;
  for (int i = 0; i < n; i++) {
    long long w = z1;
    cnt[(w >> 44) + 524288]++;
    z1 ^= (z1 << 13);
    z1 ^= (z1 >> 7);
    z1 ^= (z1 << 17);
  }
  int sum = 0, r = 0;
  for (int i = 0; i < 1048576; i++) {
    sum += cnt[i];
    if (sum > k) {
      r = i;
      break;
    }
  }
  int c = k - (sum - cnt[r]);
  ull z2 = x;
  vector<long long> v;
  for (int i = 0; i < n; i++) {
    long long w = z2;
    if ((w >> 44) + 524288 == r)
      v.push_back(z2);
    z2 ^= (z2 << 13);
    z2 ^= (z2 >> 7);
    z2 ^= (z2 << 17);
  }
  sort(v.begin(), v.end());
  cout << v[c] << endl;
  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef unsigned long long ull;
int x, n, k, cnt[1050000];
int main() {
  cin >> n >> k >> x;
  k--;
  ull z1 = x;
  for (int i = 0; i < n; i++) {
    long long w = z1;
    cnt[(w >> 44) + 524288]++;
    z1 ^= (z1 << 13);
    z1 ^= (z1 >> 7);
    z1 ^= (z1 << 17);
  }
  int sum = 0, r = 0;
  for (int i = 0; i < 1048576; i++) {
    sum += cnt[i];
    if (sum > k) {
      r = i;
      break;
    }
  }
  int c = k - (sum - cnt[r]);
  ull z2 = x;
  vector<long long> v;
  for (int i = 0; i < n; i++) {
    long long w = z2;
    if ((w >> 44) + 524288 == r)
      v.push_back(z2);
    z2 ^= (z2 << 13);
    z2 ^= (z2 >> 7);
    z2 ^= (z2 << 17);
  }
  sort(v.begin(), v.end());
  cout << v[c] << endl;
  return 0;
}
Problem p01639 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb emplace_back

ll bucket[1 << 16];

int main() {
  int n, k, x0;
  cin >> n >> k >> x0;
  k--;

  if (x0 == 0) {
    cout << 0 << endl;
    return 0;
  }

  ull x = x0;
  rep(i, n) {
    bucket[uint16_t((x >> (64 - 16)) + (1 << 15))]++;
    x ^= x << 13;
    x ^= x >> 7;
    x ^= x << 17;
  }

  ll key;
  for (key = 0; k - bucket[key] >= 0; key++) {
    k -= bucket[key];
  }

  vector<ll> v;
  x = x0;
  rep(i, n) {
    if (uint16_t((x >> (64 - 16)) + (1 << 15)) == key) {
      v.pb(x);
    }
    x ^= x << 13;
    x ^= x >> 7;
    x ^= x << 17;
  }

  sort(all(v));
  cout << v[k] << endl;
}

Error: MLE

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb emplace_back

ll bucket[1 << 16];

int main() {
  int n, k, x0;
  cin >> n >> k >> x0;
  k--;

  ull x = x0;
  rep(i, n) {
    bucket[uint16_t((x >> (64 - 16)) + (1 << 15))]++;
    x ^= x << 13;
    x ^= x >> 7;
    x ^= x << 17;
  }

  uint16_t key;
  for (key = 0; k - bucket[key] >= 0; key++) {
    k -= bucket[key];
  }

  vector<ll> v;
  x = x0;
  rep(i, n) {
    if (uint16_t((x >> (64 - 16)) + (1 << 15)) == key) {
      v.pb(x);
    }
    x ^= x << 13;
    x ^= x >> 7;
    x ^= x << 17;
  }

  sort(all(v));
  cout << v[k] << endl;
}
Problem p01639 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

constexpr int BACKET_SIZE = 5000;

unsigned long long x;

inline void init(int x0) { x = x0; }

inline long long generate() {
  long long res = static_cast<long long>(x);
  x ^= x << 13;
  x ^= x >> 7;
  x ^= x << 17;
  return res;
}

inline int get_idx(long long x) {
  static constexpr int HALF = BACKET_SIZE / 2;
  static constexpr double backet_hash =
      static_cast<double>((HALF - 1)) / LLONG_MAX;
  int res = HALF;
  if (x < 0) {
    x += LLONG_MAX;
    res = 0;
  }

  res += static_cast<int>(x * backet_hash);
  return res;
}

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

  int n, k, x0;
  cin >> n >> k >> x0;

  if (x0 == 0) {
    cout << 0 << endl;
    return EXIT_SUCCESS;
  }

  vector<int> cnt(BACKET_SIZE + 1, 0);

  init(x0);
  for (int i = 0; i < n; ++i) {
    const long long value = generate();
    ++cnt[get_idx(value)];
  }

  int idx;
  for (int i = 0; i < BACKET_SIZE; ++i) {
    if (k <= cnt[i]) {
      idx = i;
      break;
    } else {
      k -= cnt[i];
    }
  }

  vector<long long> a;
  a.reserve(cnt[idx]);

  init(x0);
  for (int i = 0; i < n; ++i) {
    const long long value = generate();
    if (get_idx(value) == idx) {
      a.emplace_back(value);
    }
  }

  sort(a.begin(), a.end());
  cout << a[k - 1] << endl;

  return EXIT_SUCCESS;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

constexpr int BACKET_SIZE = 100000;

unsigned long long x;

void init(int x0) { x = x0; }

inline long long generate() {
  long long res = static_cast<long long>(x);
  x ^= x << 13;
  x ^= x >> 7;
  x ^= x << 17;
  return res;
}

int get_idx(long long x) {
  static constexpr int HALF = BACKET_SIZE / 2;
  static constexpr double backet_hash =
      static_cast<double>((HALF - 1)) / LLONG_MAX;
  int res = HALF;
  if (x < 0) {
    x += LLONG_MAX;
    res = 0;
  }

  res += static_cast<int>(x * backet_hash);
  return res;
}

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

  int n, k, x0;
  cin >> n >> k >> x0;

  vector<int> cnt(BACKET_SIZE + 1, 0);

  init(x0);
  for (int i = 0; i < n; ++i) {
    const long long value = generate();
    ++cnt[get_idx(value)];
  }

  int idx;
  for (int i = 0; i < BACKET_SIZE; ++i) {
    if (k <= cnt[i]) {
      idx = i;
      break;
    } else {
      k -= cnt[i];
    }
  }

  vector<long long> a;
  a.reserve(cnt[idx]);

  init(x0);
  for (int i = 0; i < n; ++i) {
    const long long value = generate();
    if (get_idx(value) == idx) {
      a.emplace_back(value);
    }
  }

  sort(a.begin(), a.end());
  cout << a[k - 1] << endl;

  return EXIT_SUCCESS;
}
Problem p01639 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cfloat>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define NUM 9223372036854775807
#define DIVISOR 10000000000000000

int main() {

  ull count[2000];

  for (int i = 0; i < 2000; i++)
    count[i] = 0;

  ull N, K;
  ull x_0;
  scanf("%lld %lld %lld", &N, &K, &x_0);
  if (x_0 == 0) {
    printf("0\\n");
    return 0;
  }

  ull x = x_0;
  for (int i = 0; i < N; i++) {
    count[(ull)(NUM + (ll)x) / DIVISOR]++;
    x ^= x << 13;
    x ^= x >> 7;
    x ^= x << 17;
  }

  int sum = 0;
  ull loc;

  for (ull i = 0; i < 2000; i++) {
    if (sum + count[i] >= K) {
      loc = i;
      break;
    }
    sum += count[i];
  }

  vector<ll> V;

  x = x_0;
  for (int i = 0; i < N; i++) {

    if (loc == (ull)(NUM + (ll)x) / DIVISOR) {
      V.push_back(x);
    }
    x ^= x << 13;
    x ^= x >> 7;
    x ^= x << 17;
  }

  sort(V.begin(), V.end());

  printf("%lld\\n", V[(K - sum) - 1]);

  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cfloat>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define NUM 9223372036854775807
#define DIVISOR 10000000000000000

int main() {

  ull count[2000];

  for (int i = 0; i < 2000; i++)
    count[i] = 0;

  ull N, K;
  ull x_0;
  scanf("%lld %lld %lld", &N, &K, &x_0);

  ull x = x_0;
  for (int i = 0; i < N; i++) {
    count[(ull)(NUM + (ll)x) / DIVISOR]++;
    x ^= x << 13;
    x ^= x >> 7;
    x ^= x << 17;
  }

  int sum = 0;
  ull loc;

  for (ull i = 0; i < 2000; i++) {
    if (sum + count[i] >= K) {
      loc = i;
      break;
    }
    sum += count[i];
  }

  vector<ll> V;

  x = x_0;
  for (int i = 0; i < N; i++) {

    if (loc == (ull)(NUM + (ll)x) / DIVISOR) {
      V.push_back(x);
    }
    x ^= x << 13;
    x ^= x >> 7;
    x ^= x << 17;
  }

  sort(V.begin(), V.end());

  printf("%lld\\n", V[(K - sum) - 1]);

  return 0;
}
Problem p01639 (C++) — buggy submission, verdict: Memory Limit Exceeded

// #define NDEBUG

#include <algorithm>
#include <cassert>
#include <chrono>
#include <complex>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
ull mask = 1LL << 63;
int bm[1 << 16];
int main() {
  ll x0, n, k;
  cin >> n >> k >> x0;
  k--;
  if (!x0) {
    cout << "0" << endl;
    return 0;
  }
  ull x = x0;
  for (int i = 0; i < n; i++) {
    bm[(x + mask) >> 48]++;
    x ^= x << 13;
    x ^= x >> 7;
    x ^= x << 17;
  }
  ll sm = 0;
  ll u;
  for (u = 0; u < 1 << 16; u++) {
    if (k < sm + bm[u])
      break;
    sm += bm[u];
  }
  k -= sm;
  vector<ll> v;
  x = x0;
  for (int i = 0; i < n; i++) {
    if ((x + mask) >> 48 == u)
      v.push_back((ll)x);
    x ^= x << 13;
    x ^= x >> 7;
    x ^= x << 17;
  }
  sort(v.begin(), v.end());
  cout << v[k] << endl;
  return 0;
}

Error: MLE

Fixed submission:

// #define NDEBUG

#include <algorithm>
#include <cassert>
#include <chrono>
#include <complex>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
ull mask = 1LL << 63;
int bm[1 << 16];
int main() {
  ll x0, n, k;
  cin >> n >> k >> x0;
  k--;
  ull x = x0;
  for (int i = 0; i < n; i++) {
    bm[(x + mask) >> 48]++;
    x ^= x << 13;
    x ^= x >> 7;
    x ^= x << 17;
  }
  ll sm = 0;
  ll u;
  for (u = 0; u < 1 << 16; u++) {
    if (k < sm + bm[u])
      break;
    sm += bm[u];
  }
  k -= sm;
  vector<ll> v;
  x = x0;
  for (int i = 0; i < n; i++) {
    if ((x + mask) >> 48 == u)
      v.push_back((ll)x);
    x ^= x << 13;
    x ^= x >> 7;
    x ^= x << 17;
  }
  sort(v.begin(), v.end());
  cout << v[k] << endl;
  return 0;
}