Problem p03952 (C++)

Buggy submission (status: Runtime Error):
/*+lmake
 * STD = c++14
 * DEFINE += WAAUTOMATON
 */
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#ifdef WAAUTOMATON
#define debug(args...)                                                         \
  {                                                                            \
    dbg, args;                                                                 \
    cerr << endl;                                                              \
  }
#else
#define debug(args...) // Just strip off all debug tokens
#endif

struct debugger {
  template <typename T> debugger &operator,(const T &v) {
    cerr << v << " ";
    return *this;
  }
} dbg;

#define MAXN 100000
int a[2 * MAXN + 10];
bool b[MAXN + 10];
void solve(long long N, long long x) {
  if (x == 1 || x == 2 * N - 1) {
    puts("No");
    return;
  }
  puts("Yes");
  memset(b, true, sizeof(b));
  if (x == 2) {
    a[N] = 2;
    a[N - 1] = 3;
    a[N + 1] = 1;
    a[N + 2] = 4;
    b[1] = b[2] = b[3] = b[4] = false;
  } else {
    a[N] = x;
    a[N - 1] = x - 1;
    a[N + 1] = x + 1;
    a[N + 2] = x - 2;
    b[x - 1] = b[x] = b[x + 1] = b[x - 2] = false;
  }
  stack<int> s;
  for (int i = 1; i < 2 * N; ++i) {
    if (b[i])
      s.push(i);
  }
  for (int i = 1; i < 2 * N; ++i) {
    if (a[i] == 0) {
      a[i] = s.top();
      s.pop();
    }
    cout << a[i] << ' ';
  }
  puts("");
}

int main() {
#ifdef WAAUTOMATON
  // freopen("in.txt","r",stdin);
#endif
  long long x;
  long long N;
  scanf("%lld", &N);
  scanf("%lld", &x);
  solve(N, x);
  return 0;
}


Fixed submission:
/*+lmake
 * STD = c++14
 * DEFINE += WAAUTOMATON
 */
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#ifdef WAAUTOMATON
#define debug(args...)                                                         \
  {                                                                            \
    dbg, args;                                                                 \
    cerr << endl;                                                              \
  }
#else
#define debug(args...) // Just strip off all debug tokens
#endif

struct debugger {
  template <typename T> debugger &operator,(const T &v) {
    cerr << v << " ";
    return *this;
  }
} dbg;

#define MAXN 100000
int a[2 * MAXN + 10];
bool b[2 * MAXN + 10];
void solve(long long N, long long x) {
  if (x == 1 || x == 2 * N - 1) {
    puts("No");
    return;
  }
  puts("Yes");
  memset(b, true, sizeof(b));
  if (x == 2) {
    a[N] = 2;
    a[N - 1] = 3;
    a[N + 1] = 1;
    a[N + 2] = 4;
    b[1] = b[2] = b[3] = b[4] = false;
  } else {
    a[N] = x;
    a[N - 1] = x - 1;
    a[N + 1] = x + 1;
    a[N + 2] = x - 2;
    b[x - 1] = b[x] = b[x + 1] = b[x - 2] = false;
  }
  stack<int> s;
  for (int i = 1; i < 2 * N; ++i) {
    if (b[i])
      s.push(i);
  }
  for (int i = 1; i < 2 * N; ++i) {
    if (a[i] == 0) {
      a[i] = s.top();
      s.pop();
    }
    cout << a[i] << ' ';
  }
  puts("");
}

int main() {
#ifdef WAAUTOMATON
  // freopen("in.txt","r",stdin);
#endif
  long long x;
  long long N;
  scanf("%lld", &N);
  scanf("%lld", &x);
  solve(N, x);
  return 0;
}