Problem p03952 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

#define LOCAL 0

#define lli long long int
#define llu unsigned long long int
#define ld long double
#define all(v) v.begin(), v.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define si(n) scanf("%d", &n)
#define slli(n) scanf("%lld", &n);
#define ss(n) scanf("%s", n);

const long double EPS = 1e-10;
const lli MOD = 1000000007ll;
int INF = (int)1e9;
lli INFINF = (lli)1e18;
int debug = 0;

using namespace std;

lli bit_count(lli _x) {
  lli _ret = 0;
  while (_x) {
    if (_x % 2 == 1)
      _ret++;
    _x /= 2;
  }
  return _ret;
}
lli bit(lli _mask, lli _i) { return (_mask & (1 << _i)) == 0 ? 0 : 1; }
lli powermod(lli _a, lli _b, lli _m = MOD) {
  lli _r = 1;
  while (_b) {
    if (_b % 2 == 1)
      _r = (_r * _a) % _m;
    _b /= 2;
    _a = (_a * _a) % _m;
  }
  return _r;
}
lli add(lli a, lli b, lli m = MOD) {
  lli x = a + b;
  while (x >= m)
    x -= m;
  return x;
}
lli sub(lli a, lli b, lli m = MOD) {
  lli x = a - b;
  while (x < 0)
    x += m;
  return x;
}
lli mul(lli a, lli b, lli m = MOD) {
  lli x = a * 1ll * b;
  x %= m;
  if (x < 0)
    x += m;
  return x;
}

int N, x;
int ans[100010];

int main() {
  if (LOCAL) {
    freopen("input.txt", "r", stdin);
    // freopen("output.txt","w",stdout);
    debug = 1;
  }
  srand(time(NULL));

  cin >> N >> x;
  if (N == 2) {
    if (x == 2) {
      cout << "Yes\n1\n2\n3";
    } else {
      cout << "No\n";
    }
    return 0;
  }
  if (x == 1 || x == 2 * N - 1) {
    cout << "No\n";
    return 0;
  }

  if (N == x) {
    for (int i = 1; i <= 2 * N - 1; i++)
      ans[i] = i;
  } else if (x < N) {
    set<int> Set;
    for (int i = 1; i <= 2 * N - 1; i++)
      Set.insert(i);
    Set.erase(x);
    Set.erase(x - 1);
    Set.erase(x + 1);
    Set.erase(2 * N - 2);
    Set.erase(2 * N - 1);
    ans[N] = x;
    ans[N - 1] = x - 1;
    ans[N - 2] = 2 * N - 2;
    ans[N + 1] = 2 * N - 1;
    ans[N + 2] = x + 1;

    for (int i = N - 3, j = N + 3; !Set.empty(); i--, j++) {
      set<int>::iterator it;
      ans[i] = *Set.begin();
      Set.erase(Set.begin());
      ans[j] = *Set.begin();
      Set.erase(Set.begin());
    }
  } else {
    set<int> Set;
    for (int i = 1; i <= 2 * N - 1; i++)
      Set.insert(i);
    Set.erase(x);
    Set.erase(1);
    Set.erase(2);
    Set.erase(x - 1);
    Set.erase(x + 1);
    ans[N] = x;
    ans[N - 1] = 1;
    ans[N - 2] = x - 1;
    ans[N + 1] = x + 1;
    ans[N + 2] = 2;

    for (int i = N - 3, j = N + 3; !Set.empty(); i--, j++) {
      set<int>::iterator it;
      ans[i] = *Set.begin();
      Set.erase(Set.begin());
      ans[j] = *Set.begin();
      Set.erase(Set.begin());
    }
  }

  cout << "Yes\n";
  for (int i = 1; i <= 2 * N - 1; i++)
    cout << ans[i] << "\n";

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

#define LOCAL 0

#define lli long long int
#define llu unsigned long long int
#define ld long double
#define all(v) v.begin(), v.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define si(n) scanf("%d", &n)
#define slli(n) scanf("%lld", &n);
#define ss(n) scanf("%s", n);

const long double EPS = 1e-10;
const lli MOD = 1000000007ll;
int INF = (int)1e9;
lli INFINF = (lli)1e18;
int debug = 0;

using namespace std;

lli bit_count(lli _x) {
  lli _ret = 0;
  while (_x) {
    if (_x % 2 == 1)
      _ret++;
    _x /= 2;
  }
  return _ret;
}
lli bit(lli _mask, lli _i) { return (_mask & (1 << _i)) == 0 ? 0 : 1; }
lli powermod(lli _a, lli _b, lli _m = MOD) {
  lli _r = 1;
  while (_b) {
    if (_b % 2 == 1)
      _r = (_r * _a) % _m;
    _b /= 2;
    _a = (_a * _a) % _m;
  }
  return _r;
}
lli add(lli a, lli b, lli m = MOD) {
  lli x = a + b;
  while (x >= m)
    x -= m;
  return x;
}
lli sub(lli a, lli b, lli m = MOD) {
  lli x = a - b;
  while (x < 0)
    x += m;
  return x;
}
lli mul(lli a, lli b, lli m = MOD) {
  lli x = a * 1ll * b;
  x %= m;
  if (x < 0)
    x += m;
  return x;
}

int N, x;
int ans[200010];

int main() {
  if (LOCAL) {
    freopen("input.txt", "r", stdin);
    // freopen("output.txt","w",stdout);
    debug = 1;
  }
  srand(time(NULL));

  cin >> N >> x;
  if (N == 2) {
    if (x == 2) {
      cout << "Yes\n1\n2\n3";
    } else {
      cout << "No\n";
    }
    return 0;
  }
  if (x == 1 || x == 2 * N - 1) {
    cout << "No\n";
    return 0;
  }

  if (N == x) {
    for (int i = 1; i <= 2 * N - 1; i++)
      ans[i] = i;
  } else if (x < N) {
    set<int> Set;
    for (int i = 1; i <= 2 * N - 1; i++)
      Set.insert(i);
    Set.erase(x);
    Set.erase(x - 1);
    Set.erase(x + 1);
    Set.erase(2 * N - 2);
    Set.erase(2 * N - 1);
    ans[N] = x;
    ans[N - 1] = x - 1;
    ans[N - 2] = 2 * N - 2;
    ans[N + 1] = 2 * N - 1;
    ans[N + 2] = x + 1;

    for (int i = N - 3, j = N + 3; !Set.empty(); i--, j++) {
      set<int>::iterator it;
      ans[i] = *Set.begin();
      Set.erase(Set.begin());
      ans[j] = *Set.begin();
      Set.erase(Set.begin());
    }
  } else {
    set<int> Set;
    for (int i = 1; i <= 2 * N - 1; i++)
      Set.insert(i);
    Set.erase(x);
    Set.erase(1);
    Set.erase(2);
    Set.erase(x - 1);
    Set.erase(x + 1);
    ans[N] = x;
    ans[N - 1] = 1;
    ans[N - 2] = x - 1;
    ans[N + 1] = x + 1;
    ans[N + 2] = 2;

    for (int i = N - 3, j = N + 3; !Set.empty(); i--, j++) {
      set<int>::iterator it;
      ans[i] = *Set.begin();
      Set.erase(Set.begin());
      ans[j] = *Set.begin();
      Set.erase(Set.begin());
    }
  }

  cout << "Yes\n";
  for (int i = 1; i <= 2 * N - 1; i++)
    cout << ans[i] << "\n";

  return 0;
}