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

using namespace std;

const int SIZE = 1e6+6;
int blue[SIZE];
int yellow[SIZE];
int red[SIZE];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, m;
    cin >> n >> m;
    while (m-- > 0)
    {
        int type, start, end;
        cin >> start >> end >> type;
        
        if (type == 1)
        {
            yellow[start]++;
            yellow[end + 1]--;
        }
        if (type == 2)
        {
            blue[start]++;
            blue[end + 1]--;
        }
        if (type == 3)
        {
            red[start]++;
            red[end + 1]--;
        }

    }
    int sum_yellow = 0, sum_blue = 0, sum_red = 0;
    int res = 0;
    for (int i = 1; i <= n; ++i)
    {
       sum_yellow += yellow[i];
       sum_blue += blue[i];
       sum_red += red[i];
       if (sum_blue > 0 && sum_yellow > 0 && sum_red <= 0)
       {
           res++;
       }
    }
    cout << res;
}