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

bool col[4][1000005];
int n, m, res;
vector <pair <int, int> > inp[4];

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m;
	for (int i = 0, l, r, k; i < m; i++)
	{
		cin >> l >> r >> k;
		inp[k].push_back(make_pair(l, r));
	}
	
	for (int i = 1; i <= 3; i++)
		sort (inp[i].begin(), inp[i].end());
	
	for (int c = 1; c <= 3; c++)
	{
		int i = 0;
		for (auto j: inp[c])
			for (i = max(i, j.first); i <= j.second; i++)
				col[c][i] = true;
	}
	
	for (int i = 1; i <= n; i++)
		if (col[1][i] && col[2][i] && !col[3][i])
			res++;
	
	cout << res << '\n';
}