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
#include <bits/stdc++.h>
using namespace std;
vector<int>t[1000111];
int main() {
  int n, m;
  int count[4];
  count[1] = 0;
  count[2] = 0;
  count[3] = 0;


  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int a,b,c;
    scanf("%d%d%d", &a, &b, &c);
    t[a].push_back(c);
    t[b+1].push_back(-c);
  }
  int result = 0;
  for (int i = 1; i <= n; i++) {
    for(auto it : t[i]) {
      if (it > 0) {
        count[it]++;
      }
      else {
        count[-it]--;
      }
    }
    if (count[1] > 0 && count[2] > 0 && count[3] == 0) {
      result++;
    }
  }

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

  return 0;
}