Problem p03504 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPr(i, n) for (int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for (int i = (m); i <= (n); ++i)
#define rFORq(i, m, n) for (int i = (n); i >= (m); --i)
#define SCD(n) scanf("%d", &n)
#define SCD2(m, n) scanf("%d%d", &m, &n)
#define SCD3(m, n, k) scanf("%d%d%d", &m, &n, &k)
#define SCLLD(n) scanf("%lld", &n)
#define SCLLD2(m, n) scanf("%lld%lld", &m, &n)
#define SCLLD3(m, n, k) scanf("%lld%lld%lld", &m, &n, &k)
#define PB push_back
#define MP make_pair
#define ARSCD(A, N)                                                            \
  REP(i, N) { SCD(A[i]); }
#define ARSCD1(A, N)                                                           \
  FORq(i, 1, N) { SCD(A[i]); }
#define VSCD(v, N)                                                             \
  REP(i, N) {                                                                  \
    int x;                                                                     \
    SCD(x);                                                                    \
    v.PB(x);                                                                   \
  }
#define VSCLLD(v, N)                                                           \
  REP(i, N) {                                                                  \
    long long x;                                                               \
    SCLLD(x);                                                                  \
    v.PB(x);                                                                   \
  }
#define PRINTD(n) printf("%d\n", n)
#define PRINTLLD(n) printf("%lld\n", n)
#define DEBUG printf("%s\n", "debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
using namespace std;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
////////////////////////////////////////////////////////////////////
int main() {
  int N, C;
  SCD2(N, C);
  vector<vector<int>> stc;
  static int rec[100003][31] = {};

  REP(i, N) {
    int s, t, c;
    SCD3(s, t, c);
    VI x = {s, t, c};
    stc.PB(x);
  }

  sort(stc.begin(), stc.end());

  REP(i, N) {
    FORq(j, stc[i][0], stc[i][1]) { rec[j][i] = 1; }
  }

  int M = 0;
  REP(i, 100002) {
    int m = 0;
    REP(j, 31) { m += rec[i][j]; }
    M = max(M, m);
  }

  PRINTD(M);
}

Fixed submission:
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPr(i, n) for (int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for (int i = (m); i <= (n); ++i)
#define rFORq(i, m, n) for (int i = (n); i >= (m); --i)
#define SCD(n) scanf("%d", &n)
#define SCD2(m, n) scanf("%d%d", &m, &n)
#define SCD3(m, n, k) scanf("%d%d%d", &m, &n, &k)
#define SCLLD(n) scanf("%lld", &n)
#define SCLLD2(m, n) scanf("%lld%lld", &m, &n)
#define SCLLD3(m, n, k) scanf("%lld%lld%lld", &m, &n, &k)
#define PB push_back
#define MP make_pair
#define ARSCD(A, N)                                                            \
  REP(i, N) { SCD(A[i]); }
#define ARSCD1(A, N)                                                           \
  FORq(i, 1, N) { SCD(A[i]); }
#define VSCD(v, N)                                                             \
  REP(i, N) {                                                                  \
    int x;                                                                     \
    SCD(x);                                                                    \
    v.PB(x);                                                                   \
  }
#define VSCLLD(v, N)                                                           \
  REP(i, N) {                                                                  \
    long long x;                                                               \
    SCLLD(x);                                                                  \
    v.PB(x);                                                                   \
  }
#define PRINTD(n) printf("%d\n", n)
#define PRINTLLD(n) printf("%lld\n", n)
#define DEBUG printf("%s\n", "debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
using namespace std;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
////////////////////////////////////////////////////////////////////
int main() {
  int N, C;
  SCD2(N, C);
  vector<vector<int>> stc;
  static int rec[100003][31] = {};

  REP(i, N) {
    int s, t, c;
    SCD3(s, t, c);
    VI x = {s, t, c};
    stc.PB(x);
  }

  sort(stc.begin(), stc.end());

  REP(i, N) {
    FORq(j, stc[i][0], stc[i][1]) { rec[j][stc[i][2]] = 1; }
  }

  int M = 0;
  REP(i, 100002) {
    int m = 0;
    REP(j, 31) { m += rec[i][j]; }
    M = max(M, m);
  }

  PRINTD(M);
}