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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//Adam Krawczyk
//https://main2.edu.pl/main2/courses/show/17/39/

#include <iostream>
#include <cmath>

enum eColor {
    WHITE = 0,
    YELLOW = 1,
    BLUE = 2,
    GREEN = 3,
    RED = 4,
    ORANGE = 5,
    PURPLE = 6,
    BROWN = 7
};

int* tree;

void setColor(const int color, const int L, const int R, int a, int b, const int index = 1)
{
    if(a == L && b == R)
    {
        tree[index] |= color;

        return;
    }

    int mid = (a + b - 1) / 2;

    if(mid >= R)
    {
        setColor(color, L, R, a, mid, index * 2);
    }
    else if(mid < L)
    {
        setColor(color, L, R, mid + 1, b, index * 2 + 1);
    }
    else
    {
		setColor(color, L, mid, a, mid, 2 * index);
		setColor(color, mid + 1, R, mid + 1, b, 2 * index + 1);
    }
}

int countGreen(int treeSize, int actualColor = 0, int index = 1)
{
    if(index >= treeSize)
    {
        tree[index] |= actualColor;

        return (tree[index] | actualColor) == GREEN;
    }

    return countGreen(treeSize, actualColor | tree[index], index * 2) + countGreen(treeSize, actualColor | tree[index], index * 2 + 1);
}

int main()
{
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(0);

    int n, m;
    int l, r, k;
    int treeSize;

    std::cin >> n >> m;

    treeSize = exp2( ceil( log2(n) ) );
    tree = new int[2 * treeSize];

    for(int i = 0; i < 2 * treeSize; ++i)
    {
        tree[i] = 0;
    }

    for(int i = 0; i < m; ++i)
    {
        std::cin >> l >> r >> k;

        if(k == 3)
        {
            k = RED;
        }

        setColor(k, l - 1, r - 1, 0, treeSize - 1);
    }

    std::cout << countGreen(treeSize);

    delete[] tree;

    return 0;
}