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
33
34
#include <bits/stdc++.h>

#define ll long long

int main() {
    std::ios::sync_with_stdio(false);
    using namespace std;
    ll n, m, result = 0, q = 0;
    cin >> n >> m;
    vector< pair<ll, ll> > A;
    for(ll i = 0; i < m; i++) {
        ll a, b, c;
        cin >> a >> b >> c;
        A.push_back({a, c});
        A.push_back({b + 1, -c});
    }
    sort(A.begin(), A.end());
    vector<ll> C(3, 0); // yellow, blue, red
    for(ll i = 0; i <= n; i++) {
        while(q < A.size() && A[q].first <= i) {
            if(A[q].second < 0) {
                C[-A[q].second - 1] -= 1;
            } else {
                C[A[q].second - 1] += 1;
            }
            q++;
        }
        //cout << i << ": " << C[0] << " " << C[1] << " " << C[2] << "\n";
        if(C[0] > 0 && C[1] > 0 && C[2] == 0)
            result += 1;
    }
    cout << result << "\n";
    return 0;
}