Problem p03952 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory.h>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n)-1; i >= 0; i--)

#define DEBUG(X)                                                               \
  { cout << #X << " = " << (X) << endl; }
#define PR0(A, n)                                                              \
  {                                                                            \
    cout << #A << " = ";                                                       \
    FORN(_, n) cout << A[_] << ' ';                                            \
    cout << endl;                                                              \
  }

#define MOD 1000000007
#define INF 2000000000

int GLL(LL &x) { return scanf("%lld", &x); }

int GI(int &x) { return scanf("%d", &x); }

const int MAXN = 100010;
int res[MAXN];

int n, x;

set<int> used;

int main() {
  GI(n);
  GI(x);

  FOR1(i, 2 * n - 1) used.insert(i);

  if (x == 1 || x == 2 * n - 1) {
    printf("No\n");
    return 0;
  } else {
    printf("Yes\n");
    memset(res, 0, sizeof res);

    res[n - 1] = x - 1;
    used.erase(x - 1);
    res[n] = x;
    used.erase(x);
    res[n + 1] = x + 1;
    used.erase(x + 1);

    if (n > 2) {
      if (x + 2 <= n) {
        res[n - 2] = x + 2;
        used.erase(x + 2);
      } else { // x-2 >= 1
        res[n + 2] = x - 2;
        used.erase(x - 2);
      }
    }

    FOR1(i, 2 * n - 1) {
      if (res[i] == 0) {
        res[i] = *used.begin();
        used.erase(res[i]);
      }

      printf("%d\n", res[i]);
    }
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory.h>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n)-1; i >= 0; i--)

#define DEBUG(X)                                                               \
  { cout << #X << " = " << (X) << endl; }
#define PR0(A, n)                                                              \
  {                                                                            \
    cout << #A << " = ";                                                       \
    FORN(_, n) cout << A[_] << ' ';                                            \
    cout << endl;                                                              \
  }

#define MOD 1000000007
#define INF 2000000000

int GLL(LL &x) { return scanf("%lld", &x); }

int GI(int &x) { return scanf("%d", &x); }

const int MAXN = 200010;
int res[MAXN];

int n, x;

set<int> used;

int main() {
  GI(n);
  GI(x);

  FOR1(i, 2 * n - 1) used.insert(i);

  if (x == 1 || x == 2 * n - 1) {
    printf("No\n");
    return 0;
  } else {
    printf("Yes\n");
    memset(res, 0, sizeof res);

    res[n - 1] = x - 1;
    used.erase(x - 1);
    res[n] = x;
    used.erase(x);
    res[n + 1] = x + 1;
    used.erase(x + 1);

    if (n > 2) {
      if (x + 2 <= n) {
        res[n - 2] = x + 2;
        used.erase(x + 2);
      } else { // x-2 >= 1
        res[n + 2] = x - 2;
        used.erase(x - 2);
      }
    }

    FOR1(i, 2 * n - 1) {
      if (res[i] == 0) {
        res[i] = *used.begin();
        used.erase(res[i]);
      }

      printf("%d\n", res[i]);
    }
  }

  return 0;
}