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 <bits/stdc++.h>


using namespace std;


const int N_COLORS = 3;


int main() {
    ios_base::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;

    vector <vector<int>> cnt(N_COLORS, vector <int> (n, 0));

    while (m--) {
        int l, r, col;
        cin >> l >> r >> col; l--; r--; col--;

        cnt[col][l]++;

        if (r < n - 1) {
            cnt[col][r + 1]--;
        }
    }

    for (int col = 0; col < N_COLORS; col++) {
        for (int i = 1; i < n; i++) {
            cnt[col][i] += cnt[col][i - 1];
        }
    }

    int cntGreen = 0;

    for (int i = 0; i < n; i++) if (cnt[0][i] && cnt[1][i] && !cnt[2][i]) {
        cntGreen++;
    }

    cout << cntGreen << '\n';

    return 0;
}