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

using namespace std;

int main()
{
    int ope, farb, start, stop, k, lic;
    cin >> farb >> ope;
    int kolorki[3][farb];
    for (int q = 0; q < 3; q++){
        for (int w = 0; w < farb; w++){
            kolorki[q][w] = 0;
        }
    }
    for (int q = 0; q < ope; q++){
        cin >> start >> stop >> k;
        kolorki[k-1][start-1]++;
        if (stop < farb) kolorki[k-1][stop]--;
    }
    for (int q = 0; q < 3; q++){
        lic = 0;
        for (int w = 0; w < farb; w++){
            lic += kolorki[q][w];
            if (lic > 0){
                kolorki[q][w] = 1;
            }
            else kolorki[q][w] = 0;
            //cout << kolorki[q][w] << " ";
        }
        //cout << '\n';
    }
    lic = 0;
    for (int q = 0; q < farb; q++){
        if (kolorki[0][q] == 1 && kolorki[1][q] == 1 && kolorki[2][q] == 0){
            lic++;
        }
    }
    cout << lic;
}