Problem p03952 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define CLEAR(v) memset(v, 0, sizeof(v))
#define MP(a, b) make_pair((a), (b))
#define ABS(a) ((a) > 0 ? (a) : -(a))
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)

#define YES "Yes"
#define NO "No"

int res[100000];

int main(int argc, char **argv) {
  int n, x;
  cin >> n >> x;
  if (x == 1 || x == 2 * n - 1) {
    cout << NO << endl;
    return 0;
  }
  cout << YES << endl;
  REP(i, 2 * n - 1) res[i] = i + 1;
  if (n == 3) {
    if (x == 2) {
      res[0] = 3;
      res[1] = 5;
      res[2] = 2;
      res[3] = 1;
      res[4] = 4;
    } else if (x == 4) {
      res[0] = 3;
      res[1] = 1;
      res[2] = 4;
      res[3] = 5;
      res[4] = 2;
    }
  } else if (n != 2) {
    if (x == 2) {
      swap(res[n - 2], res[2 * n - 2]);
      swap(res[n - 1], res[x - 1]);
      swap(res[n], res[0]);
      swap(res[n + 1], res[2 * n - 3]);
    } else {
      swap(res[n - 2], res[0]);
      swap(res[n - 1], res[x - 1]);
      swap(res[n], res[2 * n - 2]);
      swap(res[n + 1], res[1]);
    }
  }
  REP(i, 2 * n - 1) cout << res[i] << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define CLEAR(v) memset(v, 0, sizeof(v))
#define MP(a, b) make_pair((a), (b))
#define ABS(a) ((a) > 0 ? (a) : -(a))
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)

#define YES "Yes"
#define NO "No"

int res[200000];

int main(int argc, char **argv) {
  int n, x;
  cin >> n >> x;
  if (x == 1 || x == 2 * n - 1) {
    cout << NO << endl;
    return 0;
  }
  cout << YES << endl;
  REP(i, 2 * n - 1) res[i] = i + 1;
  if (n == 3) {
    if (x == 2) {
      res[0] = 3;
      res[1] = 5;
      res[2] = 2;
      res[3] = 1;
      res[4] = 4;
    } else if (x == 4) {
      res[0] = 3;
      res[1] = 1;
      res[2] = 4;
      res[3] = 5;
      res[4] = 2;
    }
  } else if (n != 2) {
    if (x == 2) {
      swap(res[n - 2], res[2 * n - 2]);
      swap(res[n - 1], res[x - 1]);
      swap(res[n], res[0]);
      swap(res[n + 1], res[2 * n - 3]);
    } else {
      swap(res[n - 2], res[0]);
      swap(res[n - 1], res[x - 1]);
      swap(res[n], res[2 * n - 2]);
      swap(res[n + 1], res[1]);
    }
  }
  REP(i, 2 * n - 1) cout << res[i] << endl;
  return 0;
}