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
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>


int main() {
    int n, m;
    std::cin >> n >> m;

    std::vector<int> red(n+1, 0), yellow(n+1, 0), blue(n+1, 0);

    for(int i=0; i<m; i++) {
        int l, r, k;
        std::cin >> l >> r >> k;
        l--;
        r--;
        if(k == 1) {
            yellow[l]++;
            yellow[r+1]--;
        } else if(k == 2) {
            blue[l]++;
            blue[r+1]--;
        } else {
            red[l]++;
            red[r+1]--;
        }
    }

    int result = 0;
    int red_count=0, yellow_count=0, blue_count=0;
    for(int i=0; i<n; i++) {
        yellow_count += yellow[i];
        blue_count += blue[i];
        red_count += red[i];
        if(yellow_count>0 && blue_count>0 && red_count==0)
            result++;
        //std::cout << "for i=" << i << " yellow=" << yellow[i] << " blue=" << blue[i] << " red=" << red[i] << std::endl;
    }
    std::cout << result << std::endl;
}