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
#include <iostream>
using namespace std;

int main() {
	int n, m, from, to, color, counter = 0;
	cin >> n >> m;
	char* tab1 = new char[n];
	char* tab2 = new char[n];
	char* tab3 = new char[n];
	for (int i = 0; i < n; i++) {
		tab1[i] = 0;
		tab2[i] = 0;
		tab3[i] = 0;
	}
	for (int i = 0; i < m; i++) {
		cin >> from >> to >> color;
		if (color == 1)
		{
			for (int j = from; j < to; j++)
				tab1[j] = 1;
		}
		else if (color == 2)
		{
			for (int j = from; j < to; j++)
				tab2[j] = 1;
		}
		else
		{
			for (int j = from; j < to; j++)
				tab3[j] = 1;
		}
	}
	for (int i = 0; i < n; i++) {
		if ((tab1[i] = 1 && tab2[i] == 1) && tab3[i] == 0)
			counter++;
	}
	cout << counter;
	delete[] tab1;
	delete[] tab2;
	delete[] tab3;
}