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


enum color 
  { blanco = 0
  , amarillo = 1
  , azul = 2
  , rojo = 3
  };  

struct Paint {
  color a = blanco
      , b = blanco
      , c = blanco
      ;

  void add(color x) {
    if      (a == blanco) this->a = x;
    else if (b == blanco) this->b = x;
    else                  this->c = x;
  }
};

bool es_verde(Paint* p) {
  return (p->a == amarillo && p->b == azul     && ( p->c == blanco || p->c == azul || p->c == amarillo ))
      || (p->a == azul     && p->b == amarillo && ( p->c == blanco || p->c == azul || p->c == amarillo ));
}

int main() {
  int n // puszki w rzędzie
    , m // # ops
    ;
  int l, r, k;
  int count = 0;
  int min_i, max_i;
  std::ios::sync_with_stdio(false);

  std::cin >> n >> m;
  min_i = n - 1;
  max_i = 0;
  Paint cans[n];

  for(int i = 0; i < m; i++) {
    std::cin >> l >> r >> k;
    if (l < min_i) min_i = l;
    if (r > max_i) max_i = r;
    for(int j = l; j < r + 1; j++) cans[j-1].add((color)(k));
  }

  for(int i = min_i; i < max_i + 1; i++) {
    if(es_verde(&(cans[i]))) count ++;
  }

  std::cout << count << std::endl;

  return 0;
}