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
40
41
42
43
44
45
#include <bits/stdc++.h>
#define Y 1
#define B 2
#define R 4

#define COLOR 3

using namespace std;
uint_fast8_t f[1000003]; //char goes vroom

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m, l, r, k, i, j, fill, count=0;
	cin >> n >> m;
	for(i = 0; i < m; i++) {
		cin >> l >> r >> k;
		switch(k) {
			case 1:
				fill = Y;
				break;
			case 2:
				fill = B;
				break;
			case 3:
				fill = R;
				break;
			//default:
			//	fill = 8;
		}
		for(j = l; j <= r; j++) {
			f[j] |= fill;
		}
	}
	
	for(i = 1; i <= n; i++) {
		//cout << f[i] << " ";
		if(f[i] == COLOR)
			count++;
	}
	
	cout << count;
	
	return 0;
}