Problem p03717 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

/*
// ordered_set
# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
# define ordered_set tree<int, null_type,less<int>,
rb_tree_tag,tree_order_statistics_node_update>
*/

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
typedef pair<int, pii> pip;
typedef pair<pii, pii> ppp;
typedef pair<ll, ll> pll;

#define A first
#define B second
#define endl '\n'
#define sep ' '
#define all(x) x.begin(), x.end()
#define kill(x) return cout << x << endl, 0
#define SZ(x) int(x.size())
#define Sort(x) sort(all(x))
#define InTheNameOfGod                                                         \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);

ll power(ll a, ll b, ll md) {
  return (!b ? 1
             : (b & 1 ? a * power(a * a % md, b / 2, md) % md
                      : power(a * a % md, b / 2, md) % md));
}

// const ll md = 1e9 + 7;//998244353;
const int xn = 1e2 + 10;
const int xm = 1e2 + 10;
const int SQ = 320;
const int sq = 320 + 10;
const int inf = 1e9 + 10;
const ll INF = 1e18 + 10;
const int MOD = 1e9 + 7;
const int TM = 3;
const int Base = 257;

ll n, m, dp[xn][xn][xn], part[2][xn][xn], ans;
vector<pii> Q[xn];
bool flag;

int main() {
  InTheNameOfGod;

  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    int l, r, x;
    cin >> l >> r >> x;
    Q[r].push_back({l, x});
  }
  dp[0][0][0] = part[0][0][0] = 3;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < i; ++j) {
      for (int k = 0; k < max(1, j); ++k) {
        flag = false;
        for (pii q : Q[i])
          flag |= q.B != (i >= q.A) + (j >= q.A) + (k >= q.A);
        if (flag)
          continue;
        if (i > j + 1)
          dp[i][j][k] = dp[i - 1][j][k];
        else
          dp[i][j][k] = (part[0][j][k] + part[1][j][k]) % MOD;
        part[0][i][j] = (part[0][i][j] + dp[i][j][k]) % MOD;
        part[1][i][k] = (part[1][i][k] + dp[i][j][k]) % MOD;
        if (i == n)
          ans = (ans + dp[i][j][k]) % MOD;
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

/*
// ordered_set
# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
# define ordered_set tree<int, null_type,less<int>,
rb_tree_tag,tree_order_statistics_node_update>
*/

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
typedef pair<int, pii> pip;
typedef pair<pii, pii> ppp;
typedef pair<ll, ll> pll;

#define A first
#define B second
#define endl '\n'
#define sep ' '
#define all(x) x.begin(), x.end()
#define kill(x) return cout << x << endl, 0
#define SZ(x) int(x.size())
#define Sort(x) sort(all(x))
#define InTheNameOfGod                                                         \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);

ll power(ll a, ll b, ll md) {
  return (!b ? 1
             : (b & 1 ? a * power(a * a % md, b / 2, md) % md
                      : power(a * a % md, b / 2, md) % md));
}

// const ll md = 1e9 + 7;//998244353;
const int xn = 3e2 + 10;
const int xm = 1e2 + 10;
const int SQ = 320;
const int sq = 320 + 10;
const int inf = 1e9 + 10;
const ll INF = 1e18 + 10;
const int MOD = 1e9 + 7;
const int TM = 3;
const int Base = 257;

ll n, m, dp[xn][xn][xn], part[2][xn][xn], ans;
vector<pii> Q[xn];
bool flag;

int main() {
  InTheNameOfGod;

  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    int l, r, x;
    cin >> l >> r >> x;
    Q[r].push_back({l, x});
  }
  dp[0][0][0] = part[0][0][0] = 3;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < i; ++j) {
      for (int k = 0; k < max(1, j); ++k) {
        flag = false;
        for (pii q : Q[i])
          flag |= q.B != (i >= q.A) + (j >= q.A) + (k >= q.A);
        if (flag)
          continue;
        if (i > j + 1)
          dp[i][j][k] = dp[i - 1][j][k];
        else
          dp[i][j][k] = (part[0][j][k] + part[1][j][k]) % MOD;
        part[0][i][j] = (part[0][i][j] + dp[i][j][k]) % MOD;
        part[1][i][k] = (part[1][i][k] + dp[i][j][k]) % MOD;
        if (i == n)
          ans = (ans + dp[i][j][k]) % MOD;
      }
    }
  }
  cout << ans << endl;

  return 0;
}