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>
using namespace std;
pair<pair<bool, bool>, bool> stuff[1000002];
int main() {
	int n, m, l, r, licznik=0;
	short int k;
	cin >> n >> m;
	for (int a = 0; a < m; a++) {
		cin >> l >> r >> k;
		if (k == 1) {
			for (int b = l; b <= r; b++) {
				stuff[b].first.first = 1;
			}
		}
		else {
			if (k == 2) {
				for (int b = l; b <= r; b++) {
					stuff[b].first.second = 1;
				}
			}
			else {
				for (int b = l; b <= r; b++) {
					stuff[b].second = 1;
				}
			}
		}
	}
	for (int a = 1; a < n+1; a++) {
		if (stuff[a].first.first == 1 && stuff[a].first.second == 1 && stuff[a].second == 0) { licznik++; }
	}
	cout << licznik;
 }