Problem p03504 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for (int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for (int i = (n - 1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PP;
typedef long double ld;

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, c;
  cin >> n >> c;
  vector<PP> stc;
  vector<bitset<30>> end(100002);
  int imos[100002] = {};
  rep(i, n) {
    int p, q, r;
    cin >> p >> q >> r;
    stc.emplace_back(make_pair(p, q), r);
  }
  sort(all(stc), [](PP a, PP b) { return a.first.second < b.first.second; });
  rep(i, n) {
    int q = stc[i].first.second, r = stc[i].second;
    end[q].set(r);
  }
  rep(i, n) {
    int p = stc[i].first.first, q = stc[i].first.second, r = stc[i].second;
    if (end[p][r])
      imos[p + 1]++;
    else
      imos[p]++;
    imos[q + 1]--;
    eprintf("%d %d %d\n", end[p][r] * 1, p, q);
  }
  int ans = imos[0];
  repp(i, 1, 100002) {
    imos[i] += imos[i - 1];
    chmax(ans, imos[i]);
  }
  cout << ans << "\n";
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for (int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for (int i = (n - 1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PP;
typedef long double ld;

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, c;
  cin >> n >> c;
  vector<PP> stc;
  vector<bitset<31>> end(100002);
  int imos[100002] = {};
  rep(i, n) {
    int p, q, r;
    cin >> p >> q >> r;
    stc.emplace_back(make_pair(p, q), r);
  }
  sort(all(stc), [](PP a, PP b) { return a.first.second < b.first.second; });
  rep(i, n) {
    int q = stc[i].first.second, r = stc[i].second;
    end[q].set(r);
  }
  rep(i, n) {
    int p = stc[i].first.first, q = stc[i].first.second, r = stc[i].second;
    if (end[p][r])
      imos[p + 1]++;
    else
      imos[p]++;
    imos[q + 1]--;
    eprintf("%d %d %d\n", end[p][r] * 1, p, q);
  }
  int ans = imos[0];
  repp(i, 1, 100002) {
    imos[i] += imos[i - 1];
    chmax(ans, imos[i]);
  }
  cout << ans << "\n";
  return 0;
}