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
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
int tab[1000010][5];
int cur[5];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,m,l,r,c,ans=0,i;
	cin>>n>>m;
	for(i=1;i<=m;i++)
	{
		cin>>l>>r>>c;
		tab[l][c-1]++;
		tab[r+1][c-1]--;
	}
	for(i=1;i<=n;i++)
	{
		for(int j:{0,1,2})
			cur[j]+=tab[i][j];
		if((cur[0]>0)&&(cur[1]>0)&&(cur[2]==0))
			ans++;
	}
	cout<<ans<<"\n";
	return 0;
}