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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <optional>
#include <vector>

enum color {
    YELLOW = 1,
    BLUE = 2,
    RED = 3,
};

int main() {
    int32_t n, m;
    std::cin >> n >> m;

    std::vector<std::optional<int32_t>> y(n);
    std::vector<std::optional<int32_t>> b(n);
    std::vector<std::optional<int32_t>> r(n);

    for (int32_t i = 0; i < m; ++i) {
        int32_t li, ri, ki;
        std::cin >> li >> ri >> ki;
        switch (color(ki)) {
            case YELLOW:
                if (!y[li - 1] || *y[li - 1] < ri - 1)
                    y[li - 1] = std::make_optional(ri - 1);
                break;
            case BLUE:
                if (!b[li - 1] || *b[li - 1] < ri - 1)
                    b[li - 1] = std::make_optional(ri - 1);
                break;
            case RED:
                if (!r[li - 1] || *r[li - 1] < ri - 1)
                    r[li - 1] = std::make_optional(ri - 1);
                break;
        }
    }

    std::optional<int32_t> yst;
    std::optional<int32_t> bst;
    std::optional<int32_t> rst;
    int32_t score = 0;

    for (int32_t i = 0; i < n; ++i) {
        if (y[i] && (!yst || *yst < *y[i]))
            yst = y[i];
        if (b[i] && (!bst || *bst < *b[i]))
            bst = b[i];
        if (r[i] && (!rst || *rst < *r[i]))
            rst = r[i];

        if (*yst < i)
            yst = std::nullopt;
        if (*bst < i)
            bst = std::nullopt;
        if (*rst < i)
            rst = std::nullopt;

        if (yst && bst && !rst)
            score += 1;
    }


    std::cout << score << "\n";
}