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
#include <cstdio>
#include <string>
#include <utility>
#include <map>

int t[1000006][3];

int col[3];

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    int a, b, kolor;
    scanf("%d%d%d", &a, &b, &kolor);
    --kolor;
    ++t[a][kolor];
    --t[b+1][kolor];
  }
  int num = 0;
  for (int i = 1; i <= n; ++i) {
    for (int c = 0; c < 3; ++c) 
      col[c] += t[i][c];
    num += (col[0] > 0 && col[1] > 0 && col[2] == 0);
  }
  printf("%d\n", num);
  return 0;
}