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>
#define NM 1000010

using namespace std;

int n, m;
int delta[NM][3];

int main()
{
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        c--;
        delta[a][c]++;
        delta[b + 1][c]--;
    }
    int curr_a = 0;
    int curr_b = 0;
    int curr_c = 0;
    int out = 0;
    for (int i = 1; i <= n; i++)
    {
        curr_a += delta[i][0];
        curr_b += delta[i][1];
        curr_c += delta[i][2];
        if (curr_a > 0 && curr_b > 0 && curr_c == 0)
            out++;
    }
    cout << out << endl;
}