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
#include <cstdio>
using namespace std;

int color_start[1000002][4];
int color_end[1000002][4];

bool is_green(int*);

int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    for(int i = 0; i < m; ++i){
        int a,b,c;
        scanf("%d %d %d", &a, &b, &c);
        color_start[a][c]++;
        color_end[b+1][c]++;
    }

    int colors[4] = {0,0,0};
    // colors[1] -> yellow
    // colors[2] -> blue
    // colors[3] -> red
    int total_green = 0;

    for(int i = 1; i <= n; ++i){
        for (int k = 1; k <= 3; ++k){
            colors[k] += color_start[i][k] - color_end[i][k];
        }
        if(is_green(colors)) {
            total_green++;
        }
    }

    printf("%d\n", total_green);

    return 0;
}

bool is_green(int* colors) {
    return (colors[1] > 0 && colors[2] > 0 && colors[3] == 0);
}