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

using namespace std;

int main()
{
    int n, m, l, r, k;
    cin >> n;
    cin >> m;
    bool** colors = new bool*[n];
    for (short i = 0; i < n; i++) {
        colors[i] = new bool[3];
        colors[i][0] = false;
        colors[i][1] = false;
        colors[i][2] = false;
    }
    for (short i = 0; i < m; i++) {
        cin >> l >> r >> k;
        for (short j = l; j <= r; j++) {
            colors[j-1][k-1] = true;
        }
    }
    m = 0;
    for (short i = 0; i < n; i++) {
        if (colors[i][0] && colors[i][1] && !colors[i][2])
            m++;
    }
    cout << m;
}