1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>

int n, m;
int l, r, k;
int result = 0;

int intervals[3][1000001];
int color_elements[3];



using namespace std;

int main()
{
	cin >> n >> m;

	for (int i = 0; i < m; ++i) {
		cin >> l >> r >> k;

		if(intervals[k - 1][l - 1] < 1 + r - l)
			intervals[k - 1][l - 1] = 1 + r - l;
	}

	for (int i = 0; i <= n; ++i) {

		for (int j = 0; j < 3; ++j)
			if (color_elements[j] < intervals[j][i])
				color_elements[j] = intervals[j][i];

		if (color_elements[0] > 0 && color_elements[1] > 0 && color_elements[2] <= 0)
			++result;
		for (int j = 0; j < 3; ++j)
			--color_elements[j];	
	}
	cout << result << endl;

	return 0;
}