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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    vector< vector<int> > il(3, vector<int>(n, 0));
    for (int i = 0; i < m; ++i)
    {
        int l, r, k;
        cin >> l >> r >> k;
        --l;
        --r;
        --k;
        ++il[k][l];
        if (r + 1 < n)
            --il[k][r + 1];
    }
    for (int i = 0; i < 3; ++i)
        for (int j = 1; j < n; ++j)
            il[i][j] += il[i][j - 1];
    int odp = 0;
    for (int i = 0; i < n; ++i)
        odp += (il[0][i] >= 1 && il[1][i] >= 1 && il[2][i] == 0);
    cout << odp;
    return 0;
}