1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>

const int MAXN=1000005;

int M[MAXN][4];

int main() {
    std::ios_base::sync_with_stdio(0);
    int n,m;
    std::cin >> n >> m;
    for (int i=0;i<m;++i) {
        int l, r, k;
        std::cin >> l >> r >> k;
        M[l][k]++;
        M[r+1][k]--;
    }
    int c = 0;
    for (int i=1;i<=n;++i) {
        for (int j=1;j<=3;++j) M[i][j] += M[i-1][j];
        if (M[i][1] > 0 && M[i][2] > 0 &&  M[i][3] <= 0) ++c;
    }
    std::cout << c << std::endl;
    return 0;
}