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
#include <cstdio>
#include <vector>

int main() {
  int count, updates;

  scanf("%d %d", &count, &updates);

  std::vector<std::vector<int>> adds;
  std::vector<std::vector<int>> removals;
  adds.resize(count + 5);
  removals.resize(count + 5);
  
  for (int i = 0; i < updates; ++i) {
    int start, end, color;
    scanf("%d %d %d", &start, &end, &color);
    adds[start].push_back(color);
    removals[end].push_back(color);
  }

  std::vector<int> colors;
  colors.resize(4);

  int greens = 0;
  for (int i = 1; i <= count; ++i) {
    for (int color : adds[i]) {
      colors[color]++;
    }

    if (colors[1] > 0 && colors[2] > 0 && colors[3] == 0) {
      greens++;
    }

    for (int color : removals[i]) {
      colors[color]--;
    }
  }

  printf("%d\n", greens);

  return 0;
}