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
#include <stdio.h>
#include <stdlib.h>

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	int l, r, k;
	int ls[n][3];
	int rs[n][3];
	for (int i = 0; i < n; i++) {
		ls[i][0] = 0;
		ls[i][1] = 0;
		ls[i][2] = 0;
		rs[i][0] = 0;
		rs[i][1] = 0;
		rs[i][2] = 0;
	}
	for (int i = 0; i < m; i++) {
		scanf("%d %d %d", &l, &r, &k);
		k--; l--; r--;
		ls[l][k] += 1;
		if (r+1 < n) rs[r+1][k] += 1;
	}

	int green = 0;
	int count[3] = { 0 };
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 3; j++) {
			count[j] += ls[i][j];
			count[j] -= rs[i][j];
		}
		if (count[0] > 0 && count[1] > 0 && count[2] == 0) green++;
	}
	printf("%d\n", green);
	return 0;
}