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
#include <iostream>
#include <array>
#include <vector>
#include <algorithm>

using namespace std;

enum color : uint8_t
{
    white = 0b0000,

    yellow = 0b0001,
    blue = 0b0010,
    red = 0b0100,

    green = 0b0011,
    orange = 0b0101,
    violet = 0b0110,

    brown = 0b0111,
};

inline void addPaint(vector<uint8_t> &cans, int from, int to, int paint)
{
    static const array<uint8_t, 3> paintColorMap = {yellow, blue, red};

    // Use 0 based index
    --from;
    --to;
    --paint;

    for (size_t i = from; i <= to; i++)
    {
        cans[i] |= paintColorMap[paint];
    }
}

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);

    size_t paintCansCount;
    cin >> paintCansCount;
    vector<uint8_t> paintCans(paintCansCount, white);

    int operationsCount;
    cin >> operationsCount;
    while (operationsCount--)
    {
        int from, to, paint;
        cin >> from >> to >> paint;
        addPaint(paintCans, from, to, paint);
    }

    cout << count(paintCans.cbegin(), paintCans.cend(), green) << '\n';
    return 0;
}