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
#include <iostream>
using namespace std;

const int N = 1000009;
int n, m, su[3][N], a, b, k, lic;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin >>n >>m;

    for(int i=1; i <= m; i++) {
        cin >>a >>b >>k;
        su[k-1][a] += 1;
        su[k-1][b+1] -= 1;
    }

    for(int i=1; i <= n; i++) {
        for(int j=0; j<=2; j++) su[j][i] += su[j][i-1];
        if( su[0][i] > 0 && su[1][i] > 0 && su[2][i] == 0) lic++;
    }

    cout <<lic;
    
    return 0;
}