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
#include <bits/stdc++.h>
using namespace std;

int cnt[3], n, m;


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

    vector<pair<int, pair<int, int> > > vec;
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int l, r, x;
        cin >> l >> r >> x;
        vec.push_back({l, {x-1, 1}});
        vec.push_back({r+1, {x-1, -1}});
    }
    sort(vec.begin(), vec.end());
    int ptr = 0, ans = 0;
    for (int i = 1; i <= n; i++) {
        while(ptr < vec.size() && vec[ptr].first == i) {
            cnt[vec[ptr].second.first] += vec[ptr].second.second;
            ++ptr;
        }
        ans += (cnt[0] > 0 && cnt[1] > 0 && cnt[2] == 0);
    }
    cout << ans << endl;


}