Problem p02756 (C++)

Buggy submission (status: Runtime Error):
//------------------------------------------------------------------------------MANAS
//UNIYAL--------------------------------------------------------- 																				NEVER GIVE UP
#include <bits/stdc++.h>
using namespace std;
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pii pair<ll, ll>
#define INF 0x3f3f3f3f
#define mod 100000007
#define testcases()                                                            \
  ll t;                                                                        \
  cin >> t;                                                                    \
  while (t--)
#define debug1(x) cout << #x << " " << x << "\n";
#define debug2(x, y) cout << #x << " " << x << " " << #y << " " << y << "\n";
#define debug3(x, y, z)                                                        \
  cout << #x << " " << x << " " << #y << " " << y << " " << #z << " " << z     \
       << "\n";
#define rep(i, start, end) for (ll i = start; i < end; i++)

//----------------------------------------------------------------------------------------------------------------------------------------------------

int main() {
  fast;
  string str;
  cin >> str;
  cin.ignore();
  int q;
  cin >> q;
  int x, y, start, end;
  vector<char> v(300000);
  start = 100005;
  end = 100004;
  for (int i = 0; i < (int)str.size(); i++) {
    v[++end] = str[i];
  }
  char ch;
  while (q--) {
    cin >> x;
    if (x == 1) {
      int c = start;
      start = end;
      end = c;
    } else {
      cin >> y;
      cin >> ch;
      if (y == 1) {
        if (start <= end) {
          --start;
        } else {
          ++start;
        }
        v[start] = ch;
      } else {
        if (start <= end) {
          ++end;
        } else {
          --end;
        }
        v[end] = ch;
      }
    }
  }
  if (start <= end) {
    for (int i = start; i <= end; i++) {
      cout << v[i];
    }
  } else {
    for (int i = start; i >= end; i--) {
      cout << v[i];
    }
  }
  return 0;
}

Fixed submission:
//------------------------------------------------------------------------------MANAS
//UNIYAL--------------------------------------------------------- 																				NEVER GIVE UP
#include <bits/stdc++.h>
using namespace std;
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pii pair<ll, ll>
#define INF 0x3f3f3f3f
#define mod 100000007
#define testcases()                                                            \
  ll t;                                                                        \
  cin >> t;                                                                    \
  while (t--)
#define debug1(x) cout << #x << " " << x << "\n";
#define debug2(x, y) cout << #x << " " << x << " " << #y << " " << y << "\n";
#define debug3(x, y, z)                                                        \
  cout << #x << " " << x << " " << #y << " " << y << " " << #z << " " << z     \
       << "\n";
#define rep(i, start, end) for (ll i = start; i < end; i++)

//----------------------------------------------------------------------------------------------------------------------------------------------------

int main() {
  fast;
  string str;
  cin >> str;
  cin.ignore();
  int q;
  cin >> q;
  int x, y, start, end;
  vector<char> v(600005);
  start = 200005;
  end = 200004;
  for (int i = 0; i < (int)str.size(); i++) {
    v[++end] = str[i];
  }
  char ch;
  while (q--) {
    cin >> x;
    if (x == 1) {
      int c = start;
      start = end;
      end = c;
    } else {
      cin >> y;
      cin >> ch;
      if (y == 1) {
        if (start <= end) {
          --start;
        } else {
          ++start;
        }
        v[start] = ch;
      } else {
        if (start <= end) {
          ++end;
        } else {
          --end;
        }
        v[end] = ch;
      }
    }
  }
  if (start <= end) {
    for (int i = start; i <= end; i++) {
      cout << v[i];
    }
  } else {
    for (int i = start; i >= end; i--) {
      cout << v[i];
    }
  }
  return 0;
}