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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <iostream>

using namespace std;

int main(){

    int n,m;

    cin>>n>>m;

    int Y[n];
    int B[n];
    int R[n];

    for(int i=0; i<n; i++){
        Y[i]=0;
        B[i]=0;
        R[i]=0;
    }

    for(int i=0; i<m; i++){
        int l,r,c;
        cin>>l>>r>>c;

        l--;
        r--;

        int range = r-l +1;
        if(c==1){
            if(Y[l]<range){
                Y[l]=range;
            }
        }
        else if(c==2){
            if(B[l]<range){
                B[l]=range;
            }
        }
        else if(c==3){
            if(R[l]<range){
                R[l]=range;
            }
        }
    }

    int tmp;

    tmp = 0;
    for(int i=0; i<n; i++){
        if(tmp<Y[i]){
            tmp = Y[i];
        }
        if(tmp>0){
            Y[i] = 1;
            tmp--;
        }
    }


    tmp = 0;
    for(int i=0; i<n; i++){
        if(tmp<B[i]){
            tmp = B[i];
        }
        if(tmp>0){
            B[i] = 1;
            tmp--;
        }
    }


    tmp = 0;
    for(int i=0; i<n; i++){
        if(tmp<R[i]){
            tmp = R[i];
        }
        if(tmp>0){
            R[i] = 1;
            tmp--;
        }
    }

    int counter = 0;

    for(int i=0; i<n; i++){
        if(Y[i]==1 && B[i]==1 && R[i]==0){
            counter++;
        }
    }

    cout<<counter<<endl;

    return 0;
}