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
48
49
50
#include <iostream>
   #include <stdio.h>
   using namespace std;

  int main() {

    int paint[1000002][4];
    for (int i = 0; i < 1000002; i++) {
      for (int j = 0; j < 4; j++) {
        paint[i][j] = 0;
      }
    }

    int n;
    int m;

    cin >> n;
    cin >> m;

    for (int i = 0; i < m; i++) {
      int l;
      int r;
      int color;

      cin >> l;
      cin >> r;
      cin >> color;

      paint[l][color]++;
      paint[r + 1][color]--;
    }

    int color[4];
    color[1] = 0;
    color[2] = 0;
    color[3] = 0;

    int count = 0;
    for (int i = 1; i <= n; i++) {
      color[1] += paint[i][1];
      color[2] += paint[i][2];
      color[3] += paint[i][3];
      if (color[1] > 0 && color[2] > 0 && color[3] == 0) {
        count++;
      }
    }

    printf("%d", count);
    return 0;
  }