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
#include <iostream>
#include <map>
#include <string>

using namespace std;


struct paint{
    int yellow=0;
    int blue=0;
    int red=0;
};

struct paint cans[1000010];

int main()
{
    int n, m;
    cin >> n >> m;
    
    for(int i=0; i<m; i++){
        int l, r, k;
        cin >> l >> r >> k;
        
        switch(k){
            case(1):
                cans[l].yellow += 1;
                cans[r+1].yellow -=1;
                break;
            case(2):
                cans[l].blue += 1;
                cans[r+1].blue -=1;
                break;
            case(3):
                cans[l].red += 1;
                cans[r+1].red -=1;
                break;
        }
    }
    
    int count = 0;
    
    paint can = cans[0];
    
    for(int i=1; i<=n; i++){
        can.yellow += cans[i].yellow;
        can.blue += cans[i].blue;
        can.red += cans[i].red;
        
        if(can.yellow >0 && can.blue >0 && can.red <=0)
            count++;
    }
    
    cout << count;
}