Language: C++

#include <stdio.h>
#include <algorithm>
#include <vector>

const int P = 1000000007;

using namespace std;

struct otrezok {
	int l, r, c;
};

otrezok o[512];
vector<otrezok> p[512];

bool operator < (otrezok a, otrezok b) {
	if (a.r == b.r) return a.l < b.l;
	return a.r < b.r;
}

int n, m;

int d[2][4][301][301];

int howMany(int l, int R, int G, int B) {
	return (l <= R) + (l <= G) + (l <= B);
}

int F(int lastVal, int curVal, int R, int G, int B, int pos) {
	pos++;
	for (int i = 0; i < p[pos].size(); i++) {
		int h = howMany(p[pos][i].l, R, G, B);
		if (h != p[pos][i].c) return 0;
	}
	return (curVal + lastVal) % P;
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++) {
		scanf("%d%d%d", &o[i].l, &o[i].r, &o[i].c);
	}
	sort(o, o + m);

	for (int i = 0; i < m; i++) {
		p[o[i].r].push_back(o[i]);
	}

	d[0][1][0][0] = 1;
	d[0][2][0][0] = 1;
	d[0][3][0][0] = 1;

	int cur = 0;
	for (int i = 1; i < n; i++) {
		cur = 1 - cur;
		memset(d[cur], 0, sizeof(d[cur]));
		for (int j = 1; j <= 3; j++) {
			for (int c1 = 0; c1 <= n; c1++) {
				for (int c2 = 0; c2 <= n; c2++) {

					for (int h = 1; h <= 3; h++) {
						if (h == j) {

							if (h == 1) { //RGB
								d[cur][j][c1][c2] = F(d[1 - cur][j][c1][c2], d[1 - cur][j][c1][c2], i, c1, c2, i);
							}
							else
							if (h == 2) { //GRB
								d[cur][j][c1][c2] = F(d[1 - cur][j][c1][c2], d[1 - cur][j][c1][c2], c1, i, c2, i);
							}
							else
							if (h == 3) { //BRG
								d[cur][j][c1][c2] = F(d[1 - cur][j][c1][c2], d[1 - cur][j][c1][c2], c1, c2, i, i);
							}
						}
						else {
							//RGB
							//GRB
							//BRG
							if (h == 1) { //RED
								if (j == 2) { //WAS GREEN
									//     R    G     B                G   R   B
									d[cur][h][i - 1][c2] = F(d[1 - cur][j][c1][c2], d[cur][h][i - 1][c2], i, i - 1, c2, i);
								}
								else { //WAS BLUE
									//     R   G    B                  B   R   G
									d[cur][h][c2][i - 1] = F(d[1 - cur][j][c1][c2], d[cur][h][c2][i - 1], i, c2, i - 1, i);
								}
							}

							if (h == 2) { //GREEN
								if (j == 1) { //WAS RED
									//     G    R    B                 R   G   B
									d[cur][h][i - 1][c2] = F(d[1 - cur][j][c1][c2], d[cur][h][i - 1][c2], i - 1, i, c2, i);
								}
								else { //WAS BLUE
									//     G   R    B                  B   R   G
									d[cur][h][c1][i - 1] = F(d[1 - cur][j][c1][c2], d[cur][h][c1][i - 1], c1, i, i - 1, i);
								}
							}
							if (h == 3) { //BLUE
								if (j == 1) { //RED
									//     B    R    G                 R   G   B
									d[cur][h][i - 1][c1] = F(d[1 - cur][j][c1][c2], d[cur][h][i - 1][c1], i - 1, c1, i, i);
								}
								else { //GREEN
									//     B   R    G                  G   R   B
									d[cur][h][c1][i - 1] = F(d[1 - cur][j][c1][c2], d[cur][h][c1][i - 1], c1, i - 1, i, i);
								}
							}
						}
					}

				}
			}
		}
	}

	int total = 0;
	for (int i = 1; i <= 3; i++) {
		for (int j = 0; j <= n; j++) {
			for (int k = 0; k <= n; k++) {
				total = (total + d[cur][i][j][k]) % P;
			}
		}
	}

	printf("%d\n", total);

	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:56:17: error: 'memset' was not declared in this scope
   56 |                 memset(d[cur], 0, sizeof(d[cur]));
      |                 ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    3 | #include <vector>
  +++ |+#include <cstring>
    4 |