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
#define _CRT_SECURE_NO_WARNINGS 1
#define _WINSOCK_DEPRECATED_NO_WARNINGS 1

#include <iostream>
#include <string>
using namespace std;

int colors[4][1000100];

int main()
{
    int n, m;
    scanf("%d%d", &n, &m);


    // = {};
  
    while (m-- > 0)
    {
        int l, r, k;
        scanf("%d%d%d", &l, &r, &k);
        colors[k][l]++;
        colors[k][r+1]--;
    }
    int y = 0;
    int b = 0;
    int r = 0;
    int green = 0;
    for (int i = 0; i < 1000100; ++i)
    {
        y += colors[1][i];
        b += colors[2][i];
        r += colors[3][i];
        if (y > 0 && b > 0 && r == 0)
        {
            green++;
        }
    }
    printf("%d", green);
}