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
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

#define zolty     1
#define niebieski 2
#define czerwony  3

int main()
{
    int n, m;
    vector<pair<int, int>> begins;
    vector<pair<int, int>> ends;
    
    scanf("%d%d", &n, &m);
    while (m--)
    {
        int l, r, k;
        
        scanf("%d%d%d", &l, &r, &k);
        begins.push_back(make_pair(l, k));
        ends.push_back(make_pair(r, k));
    }
    
    begins.push_back(make_pair(n+1, 0));
    ends.push_back(make_pair(n+1, 0));
    
    sort(begins.begin(), begins.end());
    sort(ends.begin(), ends.end());
    
    int cnt = 0;
    int ib = 0;
    int ie = 0;
    int colors[4] = {};
    
    for (int i = 1; i <= n; i++)
    {
        while (begins[ib].first == i)
            colors[begins[ib++].second]++;
        
        if (colors[zolty] > 0 && colors[niebieski] > 0 && colors[czerwony] == 0)
            cnt++;
        
        while (ends[ie].first == i)
            colors[ends[ie++].second]--;
            
    }
    
    printf("%d\n", cnt);
    
    return 0;
}