Problem p02756 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int, int> P;
#define vrep(v, n)                                                             \
  for (int i = 0; i < n; i++) {                                                \
    cin >> v.at(i);                                                            \
  } // 配列vにn個の要素を入力する
#define rep(i, l, n) for (int i = l; i < (int)(n); i++)
#define repn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back

const int mod = 1000000007;
const int inf = 1e9;

bool even(int n) {
  if (n % 2 == 0)
    return true;
  else
    return false;
}

string rev(string s) {
  int n = s.size();
  string rev_s;
  rep(i, 0, n) { rev_s += s[n - 1 - i]; }
  return rev_s;
}

int main() {
  string s;
  deque<char> deq;
  cin >> s;
  rep(i, 0, s.length()) deq.push_back(s[i]);
  int cnt = 0;
  int n;
  cin >> n;
  rep(i, 0, n) {
    int q;
    cin >> q;
    if (q == 1) {
      cnt++;
    }
    if (q == 2) {
      int t;
      char c;
      cin >> t >> c;
      if (t == 1 && even(cnt))
        deq.push_front(c);
      else if (t == 1 && !even(cnt))
        deq.push_back(c);
      else if (t == 2 && even(cnt))
        deq.push_back(c);
      else if (t == 2 && !even(cnt))
        deq.push_front(c);
    }
  }
  if (even(cnt)) {
    rep(i, 0, deq.size()) { cout << deq.at(i); }
  } else {
    for (int i = deq.size(); i >= 0; i--) {
      cout << deq.at(i);
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int, int> P;
#define vrep(v, n)                                                             \
  for (int i = 0; i < n; i++) {                                                \
    cin >> v.at(i);                                                            \
  } // 配列vにn個の要素を入力する
#define rep(i, l, n) for (int i = l; i < (int)(n); i++)
#define repn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back

const int mod = 1000000007;
const int inf = 1e9;

bool even(int n) {
  if (n % 2 == 0)
    return true;
  else
    return false;
}

string rev(string s) {
  int n = s.size();
  string rev_s;
  rep(i, 0, n) { rev_s += s[n - 1 - i]; }
  return rev_s;
}

int main() {
  string s;
  deque<char> deq;
  cin >> s;
  rep(i, 0, s.length()) deq.push_back(s[i]);
  int cnt = 0;
  int n;
  cin >> n;
  rep(i, 0, n) {
    int q;
    cin >> q;
    if (q == 1) {
      cnt++;
    }
    if (q == 2) {
      int t;
      char c;
      cin >> t >> c;
      if (t == 1 && even(cnt))
        deq.push_front(c);
      else if (t == 1 && !even(cnt))
        deq.push_back(c);
      else if (t == 2 && even(cnt))
        deq.push_back(c);
      else if (t == 2 && !even(cnt))
        deq.push_front(c);
    }
  }
  if (even(cnt)) {
    rep(i, 0, deq.size()) { cout << deq.at(i); }
  } else {
    for (int i = deq.size() - 1; i >= 0; i--) {
      cout << deq.at(i);
    }
  }
}