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
#include <iostream>
#include <algorithm>

using namespace std;

struct Oper
{
    int l, r, k;
    const bool operator<(const Oper &o)
    {
        return l<o.l;
    }
} o[1000000];
bool x[3][1000000];

int main()
{
    ios_base::sync_with_stdio(false);

    int n, m;
    cin>>n>>m;
    for (int i=0; i<m; ++i)
    {
        int l, r, k;
        cin>>l>>r>>k;
        Oper &a=o[i];
        a.l=l-1;
        a.r=r-1;
        a.k=k-1;
    }
    sort(o, o+m);
    int poz[3]={};
    for (int i=0; i<m; ++i)
    {
        Oper &a=o[i];
        int k=a.k;
        poz[k]=max(poz[k], a.l);
        for (int j=poz[k]; j<=a.r; ++j)
            x[k][j]=true;
        poz[k]=max(poz[k], a.r+1);
    }
    int wyn=0;
    for (int i=0; i<n; ++i)
        if (x[0][i] && x[1][i] && !x[2][i])
            ++wyn;
    cout<<wyn<<endl;
    return 0;
}