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
40
41
42
43
44
45
46
47
48
49
50
#include<bits/stdc++.h>
using namespace std;

const int MAX=1e6+7;
int box[MAX][3];
int mix[MAX][3];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	int n,m;
	int l,r,k;
	int i;
	int wynik=0;
	
	cin>>n>>m;
	while(m--){
		cin>>l>>r>>k;
		box[l][k-1]+=1;
		box[r+1][k-1]-=1;
	}
	for(i=1;i<=n;++i){
		mix[i][0]=mix[i-1][0]+box[i][0];
		mix[i][1]=mix[i-1][1]+box[i][1];
		mix[i][2]=mix[i-1][2]+box[i][2];
	}
	for(i=1;i<=n;++i){
		if(mix[i][0]>0 && mix[i][1]>0 && mix[i][2]==0) ++wynik;
	}
	cout<<wynik<<"\n";

/*testowanie	
	
	for(i=1;i<=n;++i){
		cout<<mix[i][0]<<" ";
	}
	cout<<endl;
	for(i=1;i<=n;++i){
		cout<<mix[i][1]<<" ";
	}
	cout<<endl;
	for(i=1;i<=n;++i){
		cout<<mix[i][2]<<" ";
	}
	cout<<endl;
*/
	
	return 0;
}