Problem p03952 (C++)

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_set>
#include <vector>
using namespace std;
#define INF (1 << 29)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define uniq(v) v.erase(unique(all(v)), v.end())

int a[100000];

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

  int n, x;
  cin >> n >> x;
  if (x == 1 || x == 2 * n - 1) {
    cout << "No" << endl;
  } else if (n == 2) {
    if (x == 2) {
      cout << "Yes" << endl;
      cout << "1\n2\n3\n";
    } else {
      cout << "No" << endl;
    }
  } else {
    memset(a, -1, sizeof(a));
    cout << "Yes" << endl;
    if (x != 2) {
      a[n - 2] = 1;
      a[n - 1] = x;
      a[n] = x + 1;
      a[n + 1] = 2;
      int idx = 0;
      for (int i = 3; i <= 2 * n - 1; i++) {
        if (i != x && i != x + 1) {
          while (a[idx] != -1)
            idx++;
          a[idx++] = i;
        }
      }
      rep(i, 2 * n - 1) cout << a[i] << endl;
    } else {
      a[n - 2] = 2 * n - 1;
      a[n - 1] = 2;
      a[n] = 1;
      a[n + 1] = 2 * n - 2;
      int idx = 0;
      for (int i = 3; i <= 2 * n - 3; i++) {
        while (a[idx] != -1)
          idx++;
        a[idx++] = i;
      }
      rep(i, 2 * n - 1) cout << a[i] << endl;
    }
  }

  return 0;
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_set>
#include <vector>
using namespace std;
#define INF (1 << 29)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define uniq(v) v.erase(unique(all(v)), v.end())

int a[200000];

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

  int n, x;
  cin >> n >> x;
  if (x == 1 || x == 2 * n - 1) {
    cout << "No" << endl;
  } else if (n == 2) {
    if (x == 2) {
      cout << "Yes" << endl;
      cout << "1\n2\n3\n";
    } else {
      cout << "No" << endl;
    }
  } else {
    memset(a, -1, sizeof(a));
    cout << "Yes" << endl;
    if (x != 2) {
      a[n - 2] = 1;
      a[n - 1] = x;
      a[n] = x + 1;
      a[n + 1] = 2;
      int idx = 0;
      for (int i = 3; i <= 2 * n - 1; i++) {
        if (i != x && i != x + 1) {
          while (a[idx] != -1)
            idx++;
          a[idx++] = i;
        }
      }
      rep(i, 2 * n - 1) cout << a[i] << endl;
    } else {
      a[n - 2] = 2 * n - 1;
      a[n - 1] = 2;
      a[n] = 1;
      a[n + 1] = 2 * n - 2;
      int idx = 0;
      for (int i = 3; i <= 2 * n - 3; i++) {
        while (a[idx] != -1)
          idx++;
        a[idx++] = i;
      }
      rep(i, 2 * n - 1) cout << a[i] << endl;
    }
  }

  return 0;
}