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
#include <bits/stdc++.h>
using namespace std;

int main() {
  std::map<std::string, int> rounds;
  int n, m;
  cin >> n >> m;
  vector<int> y(n + 2);
  vector<int> b(n + 2);
  vector<int> r(n + 2);
  for (int i = 0; i < m; i++) {
    int left, right, c;
    cin >> left >> right >> c;
    switch (c) {
    case 1:
      y[left]++;
      y[right + 1]--;
      break;
    case 2:
      b[left]++;
      b[right + 1]--;
      break;
    case 3:
      r[left]++;
      r[right + 1]--;
      break;
    default:
      continue;
    }
  }
  for (int i = 2; i <= n + 1; i++) {
    y[i] += y[i - 1];
    b[i] += b[i - 1];
    r[i] += r[i - 1];
  }
  assert(y[n + 1] == 0);
  assert(b[n + 1] == 0);
  assert(r[n + 1] == 0);
  int res = 0;
  for (int i = 1; i <= n; i++) {
    if (y[i] >= 1 && b[i] >= 1 && r[i] == 0) {
      res++;
    }
  }
  cout << res << endl;
  return 0;
}