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

using namespace std;

int main() {
    int n, m, l, r, k, is_yellow=0, is_blue=0, is_red=0, res=0;
    
    scanf("%d %d", &n, &m);

    int *yellow = new int[n+1]();
    int *blue = new int[n+1]();
    int *red = new int[n+1]();

    int *buckets[3] = { yellow, blue, red };

    for(int i=0; i<m; i++) {
        scanf("%d %d %d", &l, &r, &k);

        buckets[k-1][l-1]++;
        buckets[k-1][r]--;
    }
    
    for(int i=0; i<n; i++) {
        is_yellow += buckets[0][i];
        is_blue += buckets[1][i];
        is_red += buckets[2][i];

        if(is_yellow > 0 && is_blue > 0 && is_red <= 0) {
            res++;
        }
    }

    printf("%d", res);

    delete [] yellow;
    delete [] blue;
    delete [] red;

    return 0;
}