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

vector <pair<int, int>> start;
vector <pair<int, int>> koniec;

int tab[4];

int main(){
    ios_base::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    int a, b, c;
    for(int i = 0; i < m; i++){
        cin >> a >> b >> c;
        start.push_back({a, c});
        koniec.push_back({b + 1, c});
    }

    sort(start.begin(), start.end());
    sort(koniec.begin(), koniec.end());

    int temp1 = 0, temp2 = 0;


    int temp = 1;

    int wyn = 0;

    while(temp <= n){
        while(start[temp1].first <= temp && temp1 < m){
            tab[start[temp1].second]++;
            temp1++;
        }
        while(koniec[temp2].first <= temp && temp2 < m){
            tab[koniec[temp2].second]--;
            temp2++;
        }
        if(tab[1] > 0 && tab[2] > 0 && tab[3] == 0){
            wyn++;
        }
        //cout << temp << " " << wyn << "\n";
        temp++;
    }
    cout << wyn;

    return 0;
}