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
#include <iostream>
#include <cstdio>

using namespace std;

int V[1000002][3];
int CC[3];

int main() {
	int n,m;
	scanf("%d%d", &n, &m);
	int a,b,c;
	for (int i = 0; i < m; i++) {
		scanf("%d%d%d", &a,&b,&c);
        V[a-1][c-1]++;
        V[b][c-1]--;
    }
	
    int ret = 0;
        
    for (int i=0; i < n; i++) {
        for (int j=0;j<3;j++) {
            CC[j]+=V[i][j];       
        }
        ret += CC[0] && CC[1] && !CC[2];
    }

	printf("%d\n",ret);
    return 0;
}