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
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include <iostream>
#include <vector>
#include <map>
#define endl '\n'
using namespace std;

enum COLORS
{
    WHITE = 0,

    YELLOW = 1,
    BLUE = 2,
    RED = 4,

    GREEN = 3,
    ORANGE = 5,
    VIOLET = 6,

    BROWN = 7
};

inline string getColor(int colorValue)
{
    switch (colorValue)
    {
    case WHITE:
        return "WHITE";
        break;
    case YELLOW:
        return "YELLOW";
        break;
    case BLUE:
        return "BLUE";
        break;
    case RED:
        return "RED";
        break;
    case GREEN:
        return "GREEN";
        break;
    case ORANGE:
        return "ORANGE";
        break;
    case VIOLET:
        return "VIOLET";
        break;
    case BROWN:
        return "BROWN";
        break;
    default:
        return "UKNOWN";
        break;
    }
}

vector<int> pigments = {YELLOW, BLUE, RED};

vector<int> color;
vector<vector<int>> pigments_add;
vector<vector<int>> pigments_remove;
map<int, int> pigments_current;

int main()
{
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);

    int N, M;
    cin >> N >> M;

    color.resize(N + 1);
    pigments_add.resize(N + 2);
    pigments_remove.resize(N + 2);

    for (int i = 0; i < M; ++i)
    {
        int a, b, c;
        cin >> a >> b >> c;

        if (c == 1)
            c = YELLOW;
        else if (c == 2)
            c = BLUE;
        else
            c = RED;

        pigments_add[a].push_back(c);
        pigments_remove[b + 1].push_back(c);
    }

    int green_buckets = 0;
    for (int bucket = 1; bucket <= N; ++bucket)
    {
        for (auto &p : pigments_add[bucket])
        {
            pigments_current[p] += 1;
        }

        for (auto &p : pigments_remove[bucket])
        {
            pigments_current[p] -= 1;
        }

        for (auto &p : pigments)
        {
            if (pigments_current[p] > 0)
            {
                color[bucket] |= p;
            }
        }

        if (color[bucket] == GREEN)
        {
            green_buckets += 1;
        }
    }

    cout << green_buckets << endl;

    bool DEBUG = false;
    if (DEBUG)
    {
        cout << "DEBUG" << endl;
        for (int bucket = 1; bucket <= N; ++bucket)
        {
            cout << "[BUCKET #" << bucket << "] - COLOR: " << getColor(color[bucket]);

            cout << endl;
            cout << "\t";
            for (auto &p : pigments_add[bucket]) {
                cout << "+" << getColor(p) << ",";
            }
            cout << endl;
            cout << "\t";
            for (auto &p : pigments_remove[bucket]) {
                cout << "-" << getColor(p) << ",";
            }
            cout << endl;
        }
    }
    return 0;
}