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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

int get_color(map<int, int>& mp) {
    int acc=0;
    for(auto &kv: mp)
        if(kv.second) acc+=(1<<kv.first);

    return acc;
}

int main() {
    int n, m, l, r, k;
    
    cin >> n >> m;
    vector<int> v(n);
    vector<pair<int, int>> ops;
    while(m--) {
        cin >> l >> r >> k;
        --l; --r; k;
        ops.push_back({l, k});
        ops.push_back({r+1, -k});
    }
    
    map<int, int> acc;
    int j=0;
    sort(ops.begin(), ops.end());
    for(int i=0; i<n; ++i) {
        while(j<ops.size() && ops[j].first==i) {
            int ind = ops[j].first;
            int col = ops[j].second;
            if(col<0) --acc[-col];
            else ++acc[col];
            ++j;
        }
        v[i]=get_color(acc);
    }
    
    int res=0;
    for(auto x: v) if(x==6) ++res;
    cout << res << endl;

    return 0;
}