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
#include<bits/stdc++.h>
using namespace std;


const int N = 1e6 + 5;


int n, m, cnt[4];
vector < int > add[N], del[N];

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> m;
    while(m--){
        int l, r, x;
        cin >> l >> r >> x;
        add[l].push_back(x);
        del[r].push_back(x);
    }
    int ans = 0;
    for(int i = 1; i <= n; i++){
        for(auto it : add[i]){
            cnt[it]++;
        }
        if(cnt[1] > 0 && cnt[2] > 0 && cnt[3] == 0){
            ans++;
        }
        for(auto it : del[i]){
            cnt[it]--;
        }
    }
    cout << ans;
}