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
46
47
48
49
#include <bits/stdc++.h>
#define ff first
#define ss second

using namespace std;

int n, m;
vector<pair<pair<int,int>,int>> ops; 

int main()
{
	scanf("%d %d", &n, &m);
	
	int l, r, k;
	
	for (int i = 0; i < m; ++i)
	{
		scanf("%d %d %d", &l, &r, &k);
		
		ops.push_back({{l, r}, k});
	}
	
	sort(ops.begin(), ops.end());
	
	int idx = 0, yel = -1, blu = -1, red = -1;
	int wynik = 0;
	
	for (int i = 0; i < n; ++i)
	{
		while(ops[idx].ff.ff == i)
		{
			if(ops[idx].ss == 1)
				yel = max(yel, ops[idx].ff.ss);
			else if(ops[idx].ss == 2)
				blu = max(blu, ops[idx].ff.ss);
			else
				red = max(red, ops[idx].ff.ss);
				
			++idx;
		}
		
		if(i <= yel && i <= blu && i > red)
			++wynik;
	}
	
	printf("%d\n", wynik);
	
	return 0;
}