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
#include <iostream>
using namespace std;
int color, l, r;
int n = 1000001;
int m = 1000001;
int yellow[1000001];
int blue[1000001];
int red[1000001];
int input[1000001][3];
int counter_yellow, counter_blue, counter_red;
int green_counter = 0;

int main()
{
    cin >> n;
    cin >> m;
    // we will setup r one place further to the right
    for (int i = 0; i < m; i++)
    {
        cin >> input[i][0];
        cin >> input[i][1];
        cin >> input[i][2];
    }
    for (int i = 0; i < m; i++)
    {
        l = input[i][0] - 1;
        r = input[i][1] - 1;
        color = input[i][2];
        if (color == 1)
        {
            yellow[l] += 1;
            yellow[r + 1] -= 1;
        }
        else if (color == 2)
        {
            blue[l] += 1;
            blue[r + 1] -= 1;
        }
        else if (color == 3)
        {
            red[l] += 1;
            blue[r + 1] -= 1;
        }
    }

    for (int i = 0; i < n; i++)
    {
        counter_yellow += yellow[i];
        counter_blue += blue[i];
        counter_red += red[i];
        if (counter_yellow > 0 && counter_blue > 0 && counter_red <= 0)
        {
            green_counter += 1;
        }
    }
    cout << green_counter << endl;

    return 0;
}