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

struct color_t {
	int comp[3] {};
};

int main() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr);
	int n, m;
	std::cin >> n >> m;
	std::vector<color_t> changes(n);
	for (int i = 0; i < m; i++) {
		int l, r, k;
		std::cin >> l >> r >> k;
		l--;
		k--;
		changes[l].comp[k]++;
		if (r != n)
			changes[r].comp[k]--;
	}
	color_t color;
	int r = 0;
	for (const auto& change : changes) {
		for (int i = 0; i < 3; i++) {
			color.comp[i] += change.comp[i];
		}
		if (color.comp[0] && color.comp[1] && !color.comp[2])
			r++;
	}
	std::cout << r << '\n';
	return 0;
}