Problem p02802 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i, n, m) for (int i = (n); i < (m); i++)
#define rep_d(i, n, m) for (int i = (n)-1; i >= (m); i--)
#define sort_asc(X) sort((X).begin(), (X).end())
#define sort_desc(X) sort((X).begin(), (X).end(), greater<>())

template <class T> bool chmax(T &a, T b);
template <class T> bool chmin(T &a, T b);
int *eratosthenes(int N);
bool bit_search(int pattern, int N);
template <class T> void cumulative_sum(T array, size_t N);

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

int main(void) {
  int N, M;
  cin >> N >> M;
  vector<pair<int, bool>> vec(M);
  rep(i, 0, M) {
    int p;
    string s;
    cin >> p >> s;
    if (s == "AC") {
      vec[i] = make_pair(p - 1, true);
    } else {
      vec[i] = make_pair(p - 1, false);
    }
  }
  vector<bool> qs(N, false);
  vector<int> cnt_vec(N, 0);
  int cnt_ac = 0, cnt_wa = 0;
  rep(i, 0, M) {
    if (!qs[vec[i].first]) {
      if (vec[i].second) {
        cnt_ac++;
        qs[vec[i].first] = true;
      } else {
        cnt_vec[vec[i].first]++;
      }
    }
  }
  rep(i, 0, M) {
    if (qs[vec[i].first])
      cnt_wa += cnt_vec[i];
  }
  cout << cnt_ac << " " << cnt_wa << endl;
}
// 100000 7
// 7777 AC
// 7777 AC
// 7777 AC
// 1 WA
// 1 AC
// 1 AC
// 1 AC
int *eratosthenes(int N) {
  int *prime_array = new int[N + 1];
  int lim = N;
  prime_array[0] = 0;
  prime_array[1] = 0;
  rep(i, 2, N + 1) { prime_array[i] = 1; }
  rep(i, 2, lim) {
    if (prime_array[i] == 0)
      continue;
    lim = N / i;
    for (int j = i * 2; j < N + 1; j += i) {
      prime_array[j] = 0;
    }
  }
  return prime_array;
}
template <class T> void cumulative_sum(T array, size_t N) {
  rep(i, 1, N + 1) { array[i] += array[i - 1]; }
}
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
bool bit_search(int pattern, int N) {
  int cnt = 0;
  rep(bit, 0, N) {
    if (pattern & (1 << bit)) {
      cnt++;
    }
  }
  return true;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i, n, m) for (int i = (n); i < (m); i++)
#define rep_d(i, n, m) for (int i = (n)-1; i >= (m); i--)
#define sort_asc(X) sort((X).begin(), (X).end())
#define sort_desc(X) sort((X).begin(), (X).end(), greater<>())

template <class T> bool chmax(T &a, T b);
template <class T> bool chmin(T &a, T b);
int *eratosthenes(int N);
bool bit_search(int pattern, int N);
template <class T> void cumulative_sum(T array, size_t N);

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

int main(void) {
  int N, M;
  cin >> N >> M;
  vector<pair<int, bool>> vec(M);
  rep(i, 0, M) {
    int p;
    string s;
    cin >> p >> s;
    if (s == "AC") {
      vec[i] = make_pair(p - 1, true);
    } else {
      vec[i] = make_pair(p - 1, false);
    }
  }
  vector<bool> qs(N, false);
  vector<int> cnt_vec(N, 0);
  int cnt_ac = 0, cnt_wa = 0;
  rep(i, 0, M) {
    if (!qs[vec[i].first]) {
      if (vec[i].second) {
        cnt_ac++;
        qs[vec[i].first] = true;
      } else {
        cnt_vec[vec[i].first]++;
      }
    }
  }
  rep(i, 0, N) {
    if (qs[i])
      cnt_wa += cnt_vec[i];
  }
  cout << cnt_ac << " " << cnt_wa << endl;
}
// 100000 7
// 7777 AC
// 7777 AC
// 7777 AC
// 1 WA
// 1 AC
// 1 AC
// 1 AC
int *eratosthenes(int N) {
  int *prime_array = new int[N + 1];
  int lim = N;
  prime_array[0] = 0;
  prime_array[1] = 0;
  rep(i, 2, N + 1) { prime_array[i] = 1; }
  rep(i, 2, lim) {
    if (prime_array[i] == 0)
      continue;
    lim = N / i;
    for (int j = i * 2; j < N + 1; j += i) {
      prime_array[j] = 0;
    }
  }
  return prime_array;
}
template <class T> void cumulative_sum(T array, size_t N) {
  rep(i, 1, N + 1) { array[i] += array[i - 1]; }
}
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
bool bit_search(int pattern, int N) {
  int cnt = 0;
  rep(bit, 0, N) {
    if (pattern & (1 << bit)) {
      cnt++;
    }
  }
  return true;
}