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
#include <bits/stdc++.h>
using namespace std;

const int N = 1e6 + 5;

int n, m;
int pref[3][N];

int main()
{
	scanf("%d%d", &n, &m);
	while (m--) {
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		pref[c - 1][b]++;
		pref[c - 1][a - 1]--;
	}
	for (int i = n; i > 0; i--) {
		for (int j = 0; j < 3; j++) {
			pref[j][i - 1] += pref[j][i];
		}
	}
	int res = 0;
	for (int i = 1; i <= n; i++) {
		if (pref[0][i] > 0 && pref[1][i] > 0 && pref[2][i] == 0) {
			res++;
		}
	}
	printf("%d\n", res);
}