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
#include <cstdio>
#include <cstdlib>

static const int MAX_CANS = 1000 * 1000;
static const int MAX_OPS = 1000 * 1000;

int changes[MAX_CANS+1][3] = { 0 };

int main() {
    int canCount;
    int opCount;
    scanf("%d %d", &canCount, &opCount);

    while (opCount --> 0) {
        int start, end, color;
        scanf("%d %d %d", &start, &end, &color);
        changes[start-1][color-1]++;
        changes[end][color-1]--;
    }

    int greenCount = 0;

    int currColors[3] = { 0, 0, 0 };
    for (int i = 0; i < canCount; i++) {
        for (int j = 0; j < 3; j++) {
            currColors[j] += changes[i][j];
        }

        if (currColors[0] > 0 && currColors[1] > 0 && currColors[2] == 0) {
            greenCount++;
        }
    }

    printf("%d\n", greenCount);
    return 0;
}