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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int n, m, l, r, k;

    cin >> n >> m;

    vector<vector<int>> added(n, vector<int>(3));
    vector<vector<int>> removed(n, vector<int>(3));

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

        added[l][k]++;
        removed[r][k]++;
    }

    int greenCount = 0;
    vector<long long> currentMix(3);

    for (int i = 0; i < n; i++)
    {
        currentMix[0] += added[i][0];
        currentMix[1] += added[i][1];
        currentMix[2] += added[i][2];

        if (currentMix[0] > 0 && currentMix[1] > 0 && currentMix[2] == 0)
        {
            greenCount++;
        }

        currentMix[0] -= removed[i][0];
        currentMix[1] -= removed[i][1];
        currentMix[2] -= removed[i][2];
    }
    
    cout << greenCount;
}