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

using namespace std;

int main()
{
    long n, m, l, r;
    int k;
    long i, j, ret;
    bool puszki[1000000][3];

    cin >> n >> m;

    for (i = 0; i < n; i++)
        puszki[i][0] = puszki[i][1] = puszki[i][2] = false;

    for (i = 0; i < m ; i++) {
        cin >> l >> r >> k;
        for (j = l - 1; j < r; j++) {
            puszki[j][k - 1] = true;
            //cout << "xx j=" << j << " k=" << k << endl;
        }
    }

    ret = 0;
    for (i = 0; i < n; i++)
    {
        if (puszki[i][0] && puszki[i][1] && !puszki[i][2]) ret++;
        //cout << puszki[i][0] << puszki[i][1] << puszki[i][2] << endl;
    }

    cout << ret;

    return 0;
}