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
#include <iostream>
#include <vector>
using namespace std;
long green_count=0;
enum Color{white,yellow,blue,red,green,orange,purple,brown};
Color makeColor(Color current, Color to_add){
    if(current==white)
        return to_add;
    if(current==yellow){
        if(to_add==blue){
            green_count++;
            return green;
        }
        if(to_add==red)
            return orange;
    }
    if(current==blue){
        if(to_add==yellow){
            green_count++;
            return green;
        }
        if(to_add==red)
            return purple;
    }
    if(current==red){
        if(to_add==yellow)
            return orange;
        if(to_add==blue)
            return purple;
    }
    if(current==orange){
        if(to_add==blue)
            return brown;
    }
    if(current==green){
        if(to_add==red){
            green_count--;
            return brown;
        }
    }
    if(current==purple){
        if(to_add==yellow)
            return brown;
    }
    return current;
}
int main(){
    long p,ops;
    cin>>p>>ops;
    vector<Color>cans;
    cans.resize(p);
    long from,to;
    int color;
    for (int i = 0; i < ops; i++)
    {
        cin>>from>>to>>color;
        for (int i = from-1; i < to; i++)
        {
            cans[i]=makeColor(cans[i],Color(color));
        }
    }
    /*for(int i = 0;i<cans.size();i++){
        cout<<cans[i]<<endl;
    }*/
    cout<<green_count;
    return 0;
}