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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    vector<vector<bool>> color(3);
    int n, m, l, r, k;
    cin >> n >> m;
    for (auto& v : color)
        v.resize(n);
    while (m--) {
        cin >> l >> r >> k;
        for (int i = l-1; i < r; ++i)
            color[k-1][i] = true;
    }
    int ctr = 0;
    for (int i = 0; i < n; ++i)
        if (color[2][i] == false && color[0][i] == true && color[1][i] == true)
            ctr++;
    cout << ctr;
    return 0;
}