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

using namespace std;

#define f first
#define s second

const int MAXN = 1e6 + 3;

int ile[3];
int t[MAXN][3];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    int x, y, k;
    cin >> n >> m;
    while (m--) {
        cin >> x >> y >> k;
        k--;
        t[x][k]++;
        t[y + 1][k]--;
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < 3; j++)
            ile[j] += t[i][j];
        if (ile[0] > 0 && ile[1] > 0 && ile[2] == 0)
            ans++;
    }
    cout << ans;
    return 0;
}