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

using namespace std;

struct colors {
    bool yellow = false;
    bool blue = false;
    bool red = false;
};

int main()
{
    int cansQuantity;
    int n;

    int greenCounter = 0;

    cin >> cansQuantity;
    colors* c = new colors[cansQuantity];

    cin >> n;

    for (int i = 0; i < n; i++) {
        int from, to, color;
        cin >> from >> to >> color;

        if (color == 1) {
            for (int j = from - 1; j < to; j++) {
                c[j].yellow = true;
            }
        } else if (color == 2) {
            for (int j = from - 1; j < to; j++) {
                c[j].blue = true;
            }
        } else {
            for (int j = from - 1; j < to; j++) {
                c[j].red = true;
            }
        }
    }

    for (int i = 0; i < cansQuantity; i++) {
        if (c[i].yellow && c[i].blue && !(c[i].red)) {
            greenCounter++;
        }
    }

    cout << greenCounter << "\n";
}