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
#include <iostream>
//void print(int* tab, int n){
//    for(int i = 0; i < n; i++){
//        std::cout<<tab[i]<<'|';
//
//    }
//    std::cout<<'\n';
//}
//Made by Kacper Filipiak 08.12.2020

int addColor(int color, int* pointer_to_element){
    if(color == 3) color++;
    if(*pointer_to_element == color || *pointer_to_element > 3){
        return 0;
    }else{
        if(*pointer_to_element == 3){
            if (color == 4){
                *pointer_to_element += color;
                return  -1;
            }else{
                return 0;
            }
        }
        *pointer_to_element += color;
        if (*pointer_to_element == 3) return 1;
        else return 0;
    }
}
int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    int n, m, start_index, end_index, color, sum = 0;
    std::cin>>n>>m;
    int* tab = new int[n]{0};
    for(int i = 0; i < m; i++){
        std::cin>>start_index>>end_index>>color;
        for(int t = start_index - 1; t < end_index; t++){
           // print(tab, n);
            sum += addColor(color, &tab[t]);
            //print(tab, n);
        }
    }
    std::cout<<sum;
    return 0;
}