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

#define N 1000000

vector<pair<short, bool> > T[N+1];

int main () {
	ios_base::sync_with_stdio(0);
	int n, m, l, r, wynik = 0;
	short k;
	cin>>n>>m;
	for (int i = 0; i < m; ++i) {
		cin>>l>>r>>k;
		--k; --l;
		T[l].push_back(make_pair(k, false));
		T[r].push_back(make_pair(k, true));
	}
	int kol[3];
	kol[0] = kol[1] = kol[2] = 0;
	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j < T[i].size(); ++j) {
			if (T[i][j].second) --kol[T[i][j].first];
			else ++kol[T[i][j].first];
		}
		if (kol[0] && kol[1] && !kol[2]) ++wynik;
	}
	cout<<wynik;
	return 0;
}