1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdio.h>
#include <vector>

using namespace std;

int main(int argc, const char * argv[]) {
    unsigned int n,m,counter = 0;
    unsigned short l,r,k,t,colors = 0;
    scanf("%d %d", &n, &m);
    vector<unsigned short> colorsB(n);
    for (int i = 0; i < m; i++) {
        scanf("%hu %hu %hu", &l, &r, &k);
        t = 1 << (2 *(k - 1));
        colorsB[l - 1] |= t;
        colorsB[r - 1] |= 2 * t;
    }
    for (int i = 0; i < n; i++) {
        colors = colors | (colorsB[i] & 21);
        if (colors == 5) counter++;
        colors = colors & ~((colorsB[i] / 2) & 21);
    }
    printf("%d\n", counter);
    return 0;
}