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

using namespace std;

typedef pair<int, int> event_t;

int main () {
	vector<event_t> events;
	int n, m, l, r, k;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; ++i) {
		scanf("%d %d %d", &l, &r, &k);
		events.push_back(make_pair(l, k));
		events.push_back(make_pair(r + 1, -k));
	}
	sort(events.begin(), events.end());
	int res = 0;
	int ei = 0;
	int colors[3] = {0, 0, 0};
	for (int i = 1; i <= n; ++i) {
		while (ei < events.size()) {
			if (events[ei].first > i) {
				break;
			}
			int col = abs(events[ei].second);
			int delta = events[ei].second / col;
			colors[col - 1] += delta;
			++ei;
		}
		if ((colors[0] > 0) && (colors[1] > 0) && (colors[2] == 0)) {
			++res;
		}
	}
	printf("%d\n", res);
	return 0;
}