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

int main(){
    int n, m; cin>>n>>m; 
    int l, r, k; 
    bool T[n+1][4]; 
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= 3; j++)
            T[i][j] = false; 
    int suma = 0; 
    for (int i = 0; i < m; i++){
        cin>>l>>r>>k; 
        for (int j = l; j <= r; j++){
            if (T[j][k])
                continue; 
            T[j][k] = true; 
            if (T[j][1] && T[j][2]){
                if (!T[j][3])
                    suma++; 
                else if (k == 3)
                    suma--; 
            }
        }
    }
    cout<<suma<<endl; 
}