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;

const int N = 1'000'005;
const int K = 3;

int colors_add[N][K + 1];
int current_cnt[K + 1];

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

  int n, m;
  cin >> n >> m;

  while (m--) {
    int l, r, k;
    cin >> l >> r >> k;

    colors_add[l][k]++;
    colors_add[r + 1][k]--;
  }
  
  int res = 0;

  for (int i = 1; i <= n; i++) {
    for (int k = 1; k <= K; k++) {
      current_cnt[k] += colors_add[i][k];
    }

    if (current_cnt[1] > 0 && current_cnt[2] > 0 && current_cnt[3] == 0) {
      res++;
    }
  }

  cout << res << "\n";
}