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 b[3][1000005],br[3][1000005],wyn,l,r,k,n,m;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m;
    for(int i=0; i<m; ++i)
    {
        cin>>l>>r>>k;
        b[k-1][l]++;
        b[k-1][r+1]--;
    }
    for(int i=0; i<3; ++i)
        for(int j=1; j<=n; ++j)
            br[i][j]=br[i][j-1]+b[i][j];
    for(int i=1; i<=n; i++)
        if(br[0][i]>0&&br[1][i]>0&&br[2][i]==0)
            wyn++;
    cout<<wyn;
    return 0;
}