Language: C++


#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

template <uint32_t Modulus>
class modular {
public:
  using value_type = uint32_t;
  using max_type = uint64_t;

  static constexpr value_type mod = Modulus;
  static constexpr value_type mod_min = 1;
  static constexpr value_type mod_max = 2147483647;
  static_assert(mod >= mod_min, "invalid mod :: too small");
  static_assert(mod <= mod_max, "invalid mod :: too big");

  template <class T>
  static constexpr value_type normalize(T value_) {
    if (value_ < 0) {
      value_ = -value_;
      value_ %= mod;
      if (value_ == 0) return 0;
      return mod - value_;
    }
    return value_ % mod;
  }

private:
  value_type value;

public:
  constexpr modular(): value(0) { }
  template <class T>
  explicit constexpr modular(T value_): value(normalize(value_)) { }
  template <class T>
  explicit constexpr operator T() { return static_cast<T>(value); }

  constexpr value_type operator () () const { return value; }
  constexpr modular operator - () const { return modular(mod - value); }
  constexpr modular operator ~ () const { return inverse(); }

  constexpr value_type &extract() { return value; }
  constexpr modular inverse() const { return power(mod - 2); }
  constexpr modular power(max_type exp) const {
    modular res(1), mult(*this);
    while (exp > 0) {
      if (exp & 1) res *= mult;
      mult *= mult;
      exp >>= 1;
    }
    return res;
  }

  constexpr modular operator + (const modular &rhs) const { return modular(*this) += rhs; }
  constexpr modular& operator += (const modular &rhs) { 
    if ((value += rhs.value) >= mod) value -= mod; 
    return *this; 
  }

  constexpr modular operator - (const modular &rhs) const { return modular(*this) -= rhs; }
  constexpr modular& operator -= (const modular &rhs) { 
    if ((value += mod - rhs.value) >= mod) value -= mod; 
    return *this; 
  }

  constexpr modular operator * (const modular &rhs) const { return modular(*this) *= rhs; }
  constexpr modular& operator *= (const modular &rhs) { 
    value = (max_type) value * rhs.value % mod;
    return *this;
  }

  constexpr modular operator / (const modular &rhs) const { return modular(*this) /= rhs; }
  constexpr modular& operator /= (const modular &rhs) { return (*this) *= rhs.inverse(); }

  constexpr bool zero() const { return value == 0; }
  constexpr bool operator == (const modular &rhs) const { return value == rhs.value; }
  constexpr bool operator != (const modular &rhs) const { return value != rhs.value; }
  friend std::ostream& operator << (std::ostream &stream, const modular &rhs) {
    return stream << rhs.value;
  }

};

using modint = modular<1000000007>;

template <class T, std::size_t N, std::size_t I = 0>
decltype(auto) gen_vec(const std::size_t (&list)[N], typename std::enable_if<(I == N), const T&>::type value = T()) { 
  return value; 
}

template <class T, std::size_t N, std::size_t I = 0>
decltype(auto) gen_vec(const std::size_t (&list)[N], typename std::enable_if<(I != N), const T&>::type value = T()) { 
  return std::vector(list[I], gen_vec<T, N, I + 1>(list, value)); 
}

int main() {
  int N, M;
  std::cin >> N >> M;
  auto query = gen_vec<std::pair<int, int>>({ N + 1, 0 });
  for (int i = 0; i < M; ++i) {
    int l, r, x;
    std::cin >> l >> r >> x;
    query[r].emplace_back(l, x);
  }
  auto dp = gen_vec<modint>({ N + 1, N + 1, N + 1 });
  dp[0][0][0] = modint(1);
  for (int r = 0; r < N; ++r) {
    for (int g = 0; g < N; ++g) {
      for (int b = 0; b < N; ++b) {
        int i = std::max({ r, g, b }) + 1;
        for (int next: { 0, 1, 2 }) {
          int idx[] = { r, g, b };
          idx[next] = i;
          if ([&] {
            for (auto p: query[i]) {
              int cnt = 0;
              for (int k: { 0, 1, 2 }) {
                if (idx[k] >= p.first) {
                  ++cnt;
                }
              }
              if (cnt != p.second) {
                return false;
              }
            }
            return true;
          }()) {
            dp[idx[0]][idx[1]][idx[2]] += dp[r][g][b];
          }
        }
      }
    }
  }
  modint ans;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      ans += dp[N][i][j];
      ans += dp[i][N][j];
      ans += dp[i][j][N];
    }
  }
  std::cout << ans << '\n';
  return 0;
}


Compiler output:
a.cc:8:11: error: 'uint32_t' has not been declared
    8 | template <uint32_t Modulus>
      |           ^~~~~~~~
a.cc:11:22: error: 'uint32_t' does not name a type
   11 |   using value_type = uint32_t;
      |                      ^~~~~~~~
a.cc:7:1: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
    6 | #include <numeric>
  +++ |+#include <cstdint>
    7 | 
a.cc:12:20: error: 'uint64_t' does not name a type
   12 |   using max_type = uint64_t;
      |                    ^~~~~~~~
a.cc:12:20: note: 'uint64_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:14:20: error: 'value_type' does not name a type
   14 |   static constexpr value_type mod = Modulus;
      |                    ^~~~~~~~~~
a.cc:15:20: error: 'value_type' does not name a type
   15 |   static constexpr value_type mod_min = 1;
      |                    ^~~~~~~~~~
a.cc:16:20: error: 'value_type' does not name a type
   16 |   static constexpr value_type mod_max = 2147483647;
      |                    ^~~~~~~~~~
a.cc:17:17: error: 'mod' was not declared in this scope
   17 |   static_assert(mod >= mod_min, "invalid mod :: too small");
      |                 ^~~
a.cc:17:24: error: 'mod_min' was not declared in this scope
   17 |   static_assert(mod >= mod_min, "invalid mod :: too small");
      |                        ^~~~~~~
a.cc:18:17: error: 'mod' was not declared in this scope
   18 |   static_assert(mod <= mod_max, "invalid mod :: too big");
      |                 ^~~
a.cc:18:24: error: 'mod_max' was not declared in this scope
   18 |   static_assert(mod <= mod_max, "invalid mod :: too big");
      |                        ^~~~~~~
a.cc:21:20: error: 'value_type' does not name a type
   21 |   static constexpr value_type normalize(T value_) {
      |                    ^~~~~~~~~~
a.cc:32:3: error: 'value_type' does not name a type
   32 |   value_type value;
      |   ^~~~~~~~~~
a.cc:41:13: error: 'value_type' does not name a type
   41 |   constexpr value_type operator () () const { return value; }
      |             ^~~~~~~~~~
a.cc:45:13: error: 'value_type' does not name a type
   45 |   constexpr value_type &extract() { return value; }
      |             ^~~~~~~~~~
a.cc:47:27: error: 'max_type' has not been declared
   47 |   constexpr modular power(max_type exp) const {
      |                           ^~~~~~~~
a.cc: In function 'int main()':
a.cc:102:49: warning: narrowing conversion of '(N + 1)' from 'int' to 'std::size_t' {aka 'long unsigned int'} [-Wnarrowing]
  102 |   auto query = gen_vec<std::pair<int, int>>({ N + 1, 0 });
      |                                               ~~^~~
a.cc:108:21: error: 'modint' was not declared in this scope; did you mean 'mode_t'?
  108 |   auto dp = gen_vec<modint>({ N + 1, N + 1, N + 1 });
      |                     ^~~~~~
      |                     mode_t
a.cc:108:28: error: no matching function for call to 'gen_vec<<expression error> >(<brace-enclosed initializer list>)'
  108 |   auto dp = gen_vec<modint>({ N + 1, N + 1, N + 1 });
      |             ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:90:16: note: candidate: 'template<class T, long unsigned int N, long unsigned int I> decltype(auto) gen_vec(const std::size_t (&)[N], typename std::enable_if<(I == N), const T&>::type)'
   90 | decltype(auto) gen_vec(const std::size_t (&list)[N], typename std::enable_if<(I == N), const T&>::type value = T()) {
      |                ^~~~~~~
a.cc:90:16: note:   template argument deduction/substitution failed:
a.cc:108:28: error: template argument 1 is invalid
  108 |   auto dp = gen_vec<modint>({ N + 1, N + 1, N + 1 });
      |             ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:95:16: note: candidate: 'template<class T, long unsigned int N, long unsigned int I> decltype(auto) gen_vec(const std::size_t (&)[N], typename std::enable_if<(I != N), const T&>::type)'
   95 | decltype(auto) gen_vec(const std::size_t (&list)[N], typename std::enable_if<(I != N), const T&>::type value = T()) {
      |                ^~~~~~~
a.cc:95:16: note:   template argument deduction/substitution failed:
a.cc:108:28: error: template argument 1 is invalid
  108 |   auto dp = gen_vec<modint>({ N + 1, N + 1, N + 1 });
      |             ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:137:9: error: expected ';' before 'ans'
  137 |   modint ans;
      |         ^~~~
      |         ;
a.cc:140:7: error: 'ans' was not declared in this scope; did you mean 'abs'?
  140 |       ans += dp[N][i][j];
      |       ^~~
      |       abs
a.cc:145:16: error: 'ans' was not declared in this scope; did you mean 'abs'?
  145 |   std::cout << ans << '\n';
      |                ^~~
      |                abs