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
#include <algorithm>
#include <cstdio>
#include <vector>
#include <set>

using namespace std;

long a[2000004][3];

int main()
{
	long n, m, l, r, k;
	scanf("%ld %ld", &n, &m);
	for (long i = 0; i < m; ++i)
	{
		scanf("%ld %ld %ld", &l, &r, &k);
		a[l * 2][k - 1]++;
		a[r * 2 + 1][k - 1]++;
	}

	long res = 0, s1 = 0, s2 = 0, s3 = 0;
	for (long i = 1; i <= n; ++i)
	{
		s1 += a[i * 2][0];
		s2 += a[i * 2][1];
		s3 += a[i * 2][2];
		if (s1 > 0 && s2 > 0 && s3 == 0)
			++res;
		s1 -= a[i * 2 + 1][0];
		s2 -= a[i * 2 + 1][1];
		s3 -= a[i * 2 + 1][2];
	}
	printf("%ld", res);
	return 0;
}