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
#include <stdio.h>
#include <string.h>

int T[1000111][3], S[3];
int n,m;

int main()
{
    memset(T, 0, sizeof(T));
    scanf("%d %d", &n, &m);

    for (int i=0; i<m; i++) {
        int l,r,k;
        scanf("%d %d %d", &l, &r, &k);
        T[l][k-1] ++;
        T[r+1][k-1] --;
    }
    S[0] = S[1] = S[2] = 0;
    int z = 0;
    for (int i=1; i<=n; i++) {
        S[0] += T[i][0];
        S[1] += T[i][1];
        S[2] += T[i][2];
        if (S[0] && S[1] && !S[2]) z ++;
    }
    printf("%d\n", z);
    return 0;
}