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

using namespace std;
const int N = 1000001;
int increment[3][N];
int red, yellow, blue, result;

int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int l, r, k;
		cin >> l >> r >> k;
		increment[k-1][l-1]++;
		increment[k-1][r]--;
	}
	for (int i = 0; i < n; i++) {
		yellow += increment[0][i];
		blue += increment[1][i];
		red += increment[2][i];
		if (red == 0 && yellow > 0 && blue > 0) {
			result++;
		}
	}
	cout << result << "\n";
}