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
#include <bits/stdc++.h>
#define st first
#define nd second
using namespace std;
int n, m;
vector <pair <int,int> > p[3];
int a[3][1000001];


int main ()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>> n>> m;
    while (m--)
    {
        int a,b,c;
        cin>> a>> b>> c;
        p[c-1].push_back({a, 1});
        p[c-1].push_back({b+1, -1});
    }
    for (int i=0; i<3; i++)
        sort (p[i].begin(), p[i].end());

    for (int i=0; i<3; i++)
    {
        int cnt=0;
        for (int j=0; j<p[i].size()-1; j++)
        {
            cnt+=p[i][j].nd;
            for (int k=p[i][j].st; k<p[i][j+1].st; k++)
                a[i][k]=cnt;
        }
    }


    int ans=0;
        for (int i=1; i<=n; i++)
            if (a[0][i] && a[1][i] && !a[2][i])
                ans++;

            cout<< ans;

    return 0;
}