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

int x,y,z,wynik;
struct kolor{
	bool red;
	bool blue;
	bool yellow;
}e[1000002];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n,m;
	cin>>n>>m;
	for(int i = 0; i < m; i++){
		cin>>x>>y>>z;
		if(z == 1)
			for(int j = x; j <= y; j++)
				e[j].yellow = 1;
		if(z == 2)
			for(int j = x; j <= y; j++)
				e[j].blue = 1;
		if(z == 3)
			for(int j = x; j <= y; j++)
				e[j].red = 1;
	}
	for(int i = 1; i <= n; i++){
		if(e[i].blue == 1 && e[i].yellow == 1 && e[i].red == 0)
			wynik++;
	}
	cout<<wynik<<endl;
	return 0;
}