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
50
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <vector>
#define Yellow 1
#define Blue 2
#define Red 3

std::vector<int> InEvents[1000001];
std::vector<int> OutEvents[1000001];

int main()
{
    int N, M;
    scanf("%d %d", &N, &M);
    for (int i = 0; i < M; i++) {
        int l, r, k;
        scanf("%d %d %d", &l, &r, &k);
        InEvents[l].push_back(k);
        OutEvents[r].push_back(k);
    }

    int yellow = 0;
    int blue = 0;
    int red = 0;
    int result = 0;
    for (int i = 1; i < N + 1; i++) {
        for (auto x : InEvents[i]) {
            if (x == Yellow)
                yellow++;
            else if (x == Blue)
                blue++;
            else if (x == Red)
                red++;
        }

        if (blue > 0 && yellow > 0 && red == 0)
            result++;

        for (auto x : OutEvents[i]) {
            if (x == Yellow)
                yellow--;
            else if (x == Blue)
                blue--;
            else if (x == Red)
                red--;
        }
    }
    printf("%d", result);
    return 0;
}