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
31
32
#include <bits/stdc++.h>
using namespace std;
int n,m;
unordered_map<char, unordered_map<int,int>> _Cstart, _Cend;

int calculate()
{
    int res = 0;
    map<int, int> counter; 
    for(int i = 1; i<n+1;i++) {
        counter[1] += _Cstart[1][i];
        counter[2] += _Cstart[2][i];
        counter[3] += _Cstart[3][i];
        counter[1] -= _Cend[1][i-1];
        counter[2] -= _Cend[2][i-1];
        counter[3] -= _Cend[3][i-1];
        if ( counter[1] && counter[2] && !counter[3] ) res++;
    }
    return res;
}


int main() {
    cin >> n >> m;
    while( m --> 0) {
        int l,r,c;
        cin >> l >> r >> c;
        _Cstart[c][l] += 1;
        _Cend[c][r] += 1;
    }
    cout << calculate();
}