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
#include <bits/stdc++.h>

using namespace std;
int n, q;
const int N = 1e6 + 9;
int cnt[4][N];

int solv()
{
    int sol = 0;
    tuple<int, int, int> curr_sum;
    for(int i = 1; i <= n; i++) {
        get<0>(curr_sum) += cnt[1][i];
        get<1>(curr_sum) += cnt[2][i];
        get<2>(curr_sum) += cnt[3][i];
        if(get<0>(curr_sum) > 0 && get<1>(curr_sum) > 0 && get<2>(curr_sum) == 0)
            sol++;
    }
    return sol;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n >> q;
    for(int i = 0; i < q; i++) {
        int l, r, color;
        cin >> l >> r >> color;
        cnt[color][l]++;
        cnt[color][r + 1]--;
    }
    cout << solv();

    return 0;
}