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

const int maxn = 1000005;
int A[4][maxn];
int n, m, czerwony, zolty, niebieski, ans;


int main() {
    ios_base::sync_with_stdio(0); cin.tie();
    cin >> n >> m;
     for(int i = 0; i <= n; i++)
       A[1][i] = A[2][i] = A[3][i] = 0;
    
    for(int i = 0; i < m; i++){
      int l,r,k;
      cin >> l >> r >> k;
      A[k][l]++;
      A[k][r+1]--;
    }

    for(int i = 1; i <= n; i++){
      zolty += A[1][i];
      niebieski += A[2][i];
      czerwony += A[3][i];
      if(niebieski > 0 && zolty > 0 && czerwony == 0) ans++;
    }
    cout << ans;
}