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
45
46
47
48
49
50
51
52
#include <iostream>

using namespace std;

int yellow[1000007];
int blue[1000007];
int red[1000007];
int n,m;
int l,r,k;
int licz = 0;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for(int i = 0; i<m; ++i)
    {
        cin >> l >> r >> k;
        switch(k)
        {
        case 1:
            for(int j = l; j<=r; ++j)
            {
                yellow[j] = 1;
            }
            break;
        case 2:
            for(int j = l; j<=r; ++j)
            {
                blue[j] = 1;
            }
            break;
        case 3:
            for(int j = l; j<=r; ++j)
            {
                red[j] = 1;
            }
            break;
        }
    }
    for(int i = 1; i<=n; ++i)
        {
                if( (yellow[i] == 1 && blue[i] ==1) && red[i] != 1)
                {
                    licz++;
                }
        }
        cout << licz;
    return 0;
}