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
#include <iostream>
#include <vector>


using namespace std;

int main() {
    int n, m;
    cin >> n >> m;

    vector<vector<int>> lefts(n+1, vector<int>(4, 0));
    vector<vector<int>> rights(n+1, vector<int>(4, 0));


    int l, r, k;
    for (int i = 0; i < m; ++i) {
        cin >> l >> r >> k;
        lefts[l][k]++;
        rights[r][k]++;
    }
    int yellow = 0;
    int blue = 0;
    int red = 0;

    int green = 0;

    for (int bucket = 1; bucket <= n; ++bucket) {
        yellow += lefts[bucket][1];
        blue += lefts[bucket][2];
        red += lefts[bucket][3];

        if (yellow > 0 && blue > 0 && red == 0) {
            green++;
        }

        yellow -= rights[bucket][1];
        blue -= rights[bucket][2];
        red -= rights[bucket][3];

    }
    cout << green << '\n';

    return 0;
}