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
#include<bits/stdc++.h>
#define st first
#define nd second
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, m;
    cin>>n>>m;
    vector<pair<int, int> > V;
    for(int i=0; i<m; i++){
        int a, b, c;
        cin>>a>>b>>c;
        V.push_back({a, c});
        V.push_back({b+1, -c});
    }
    sort(V.begin(), V.end());
    vector<int> ile(3);
    int wsk=0, ans=0;
    for(int i=1; i<=n; i++){
        while(wsk<2*m && V[wsk].st==i){
            if(V[wsk].nd>0)ile[V[wsk].nd-1]++;
            else ile[-V[wsk].nd-1]--;
            wsk++;
        }
        if(ile[0] && ile[1] && !ile[2])ans++;
    }
    cout<<ans;
}