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 <iostream>
#include <vector>

using namespace std;

vector <int> dane;
int n, m, a, b, kolor, ile;

int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i++)
	{
		dane.push_back(0);
	}
	for (int i = 0; i < m; i++)
	{
		cin >> a >> b >> kolor;
		a -= 1;
		b -= 1;
		for (int u = a; u <= b; u++)
		{
			if (dane[u] == 0)
			{
				dane[u] += kolor;
			}
			else
			{
				if (dane[u] >= 4 && (kolor == 1 || kolor == 2)) continue;
				if (dane[u] != kolor)
				{
					dane[u] += kolor + 1;
				}
			}
		}
	}
	for (int i = 0; i < n; i++)
	{
		if (dane[i] == 4) ile++;
	}
	cout << ile;
	return 0;
}