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
#include <stdio.h>
using namespace std;

const int MAX_N = 1e6 + 2;
bool paint_cans[MAX_N][3];
// 0 - yellow
// 1 - blue
// 2 - red

int main()
{
    int hm_cans, actions;
    scanf("%i %i", &hm_cans, &actions);

    for (int i = 0; i < actions; i++)
    {
        int left, right, color; scanf("%i %i %i", &left, &right, &color);
        for (int cur = left; cur <= right; cur++) {
            paint_cans[cur-1][color-1] = true;
        }
    }

    int count_green = 0;
    for (int i = 0; i <= hm_cans; i++) {
        if(paint_cans[i][0] && paint_cans[i][1] && !paint_cans[i][2]) count_green++;
    }

    printf("%i\n", count_green);
    return 0;
}