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

using namespace std;
    //MAX SIZE  COLORS
int can[1000002][4] = {};

int main() {
    int n, m, l, r, k;
    int result = 0;

    scanf("%d",&n);
    scanf("%d",&m);

    for(int i = 0; i < m; i++) {
        scanf("%d %d %d",&l,&r,&k);
        can[l][k]++;
        can[r+1][k]--;
    }

    for(int i = 1; i <= n; i++) {
        can[i][1] += can[i-1][1];
        can[i][2] += can[i-1][2];
        can[i][3] += can[i-1][3];

        if(can[i][1] > 0 && can[i][2] > 0 && can[i][3] <= 0) {
            result++;
        }
    }

    printf("%d",result);
}