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
#include <bits/stdc++.h>

using namespace std;

int n, m;
int l, r, k;
int blue, red, yellow, res;
int tab[3][1000007];

int main()
{
    scanf("%d%d", &n, &m);
    for(int i = 1; i<=m; i++)
    {
        scanf("%d%d%d", &l, &r, &k);
        tab[k-1][l]++;
        tab[k-1][r+1]--;
    }
    for(int i = 1; i<=n; i++)
    {
        yellow+=tab[0][i];
        blue+=tab[1][i];
        red+=tab[2][i];
        if(yellow > 0 && blue > 0 && red == 0)
            res++;
    }
    printf("%d", res);
    return 0;
}