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

using namespace std;

struct point{
    int yStarts;
    int yEnds;
    int bStarts;
    int bEnds;
    int rStarts;
    int rEnds;
};

point points[1000001];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,m;
    cin>>n>>m;

    int g = 0;

    int l, r, k;

    for(int i=0; i<m; i++){
        cin>>l>>r>>k;
        switch(k){
            case 1:
                points[l-1].yStarts++;
                points[r].yEnds++;
                break;
            case 2:
                points[l-1].bStarts++;
                points[r].bEnds++;
                break;
            case 3:
                points[l-1].rStarts++;
                points[r].rEnds++;
                break;
        }
    }
    int yCount, bCount, rCount;
    yCount = bCount = rCount = 0;
    for(int i=0; i<n; i++){
        if(points[i].yStarts > 0){
            yCount+=points[i].yStarts;
        }
        if(points[i].bStarts > 0){
            bCount+=points[i].bStarts;
        }
        if(points[i].rStarts > 0){
            rCount+=points[i].rStarts;
        }
        if(points[i].yEnds > 0){
            yCount-=points[i].yEnds;
        }
        if(points[i].bEnds > 0){
            bCount-=points[i].bEnds;
        }
        if(points[i].rEnds > 0){
            rCount-=points[i].rEnds;
        }
        if(yCount > 0 && bCount > 0 && rCount == 0){
            g++;
        }
    }
    cout<<g;
    return 0;
}