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

using namespace std;

int main()
{
    int m, n;
    cin >> n >> m;
    int *yellow = new int[n + 1];
    int *blue = new int[n + 1];
    int *other = new int[n + 1];

    int r, l, k;
    for (int i = 0; i < m; i++)
    {
        cin >> r >> l >> k;
        if (k == 1)
        {
            yellow[r] = max(yellow[r], l);
        }
        else if (k == 2)
        {
            blue[r] = max(blue[r], l);
        }
        else
        {
            other[r] = max(other[r], l);
        }
    }
    int result = 0;
    int yend = 0;
    int bend = 0;
    int oend = 0;
    for (int i = 1; i <= n; i++)
    {
        if (other[i] > oend)
        {
            oend = other[i];
        }
        if (yellow[i] > yend)
        {
            yend = yellow[i];
        }
        if (blue[i] > bend)
        {
            bend = blue[i];
        }
        if (i <= yend && i <= bend && i > oend)
        {
            result++;
        }
    }
    cout<<result<<endl;
    return 0;
}