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
#include <bits/stdc++.h>
using namespace std;

struct Color
{
	bool ybr[3];
	Color()
	{
		fill(ybr, ybr+3, 0);
	}
};

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	Color* a = new Color[1000000];
	int n, m;
	cin >> n >> m;

	for (;m--;)
	{
		int l, r, k;
		cin >> l >> r >> k;
		l--; r--; k--;
		for (int i = l; i <= r; i++)
		{
			a[i].ybr[k] = 1;
		}
	}

	int res = 0;
	for (int i = 0; i < n; i++)
	{
		if ((a[i].ybr[0])&&(a[i].ybr[1])&&(!(a[i].ybr[2]))) res++;
	}

	cout << res << "\n";

	return 0;
}