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
#include<iostream>
using namespace std;

int k[1000001][3];
int curr[3];
int a, b, c, n, q;

int main() {
  ios_base::sync_with_stdio(0);

  cin >> n >> q;
  while (q--) {
    cin >> a >> b >> c;
    a--;
    b--;
    c--;
    k[a][c]++;
    k[b + 1][c]--;
  }

  int res = 0;
  for (int i = 0; i < n; i++) {
    for (int c = 0; c < 3; c++) {
      curr[c] += k[i][c];
    }
    if (curr[0] > 0 && curr[1] > 0 && curr[2] == 0) {
      res++;
    }
  }

  cout << res << endl;

  return 0;
}