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

int main() {
  constexpr std::uint32_t colors_count = 3;

  std::uint32_t n, m;
  std::cin >> n >> m;

  std::array<std::vector<std::uint32_t>, colors_count> ends;
  for (auto &c : ends) {
    c.resize(n, 0);
  }

  for (std::uint32_t i = 0; i < m; ++i) {
    std::uint32_t l, r, k;
    std::cin >> l >> r >> k;
    --l;
    --k;
    ends[k][l] = std::max(ends[k][l], r);
  }

  for (auto &ends_k : ends) {
    std::uint32_t end = 0;
    for (std::uint32_t i = 0; i < n; ++i) {
      end = std::max(end, ends_k[i]);
      ends_k[i] = i < end ? 1 : 0;
    }
  }

  std::uint32_t green_count = 0;
  for (std::uint32_t i = 0; i < n; ++i) {
    if (ends[0][i] == 1 && ends[1][i] == 1 && ends[2][i] == 0) {
      ++green_count;
    }
  }

  std::cout << green_count << '\n';

  return 0;
}