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

const int MAXI = 1e6 + 7;
int jaki[MAXI];
set <int> niebylo[4];
set <int> :: iterator it;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m, a, b, c, wyn = 0;;
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        niebylo[1].insert(i);
        niebylo[2].insert(i);
        niebylo[3].insert(i);
    }
    for(int i = 1; i <= m; i++){
        cin >> a >> b >> c;
        it = niebylo[c].lower_bound(a);
        int j = *it;
        while(j <= b){
            jaki[j] += 10;
            jaki[j] += c;
            it++;
            if(it == niebylo[c].end()){
                break;
            }
            niebylo[c].erase(j);
            j = *it;
        }
    }
    for(int i = 1; i <= n; i++){
        if(jaki[i] == 23){
            wyn++;
        }
    }
    cout << wyn << '\n';
    return 0;
}