1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 6;
int pref[maxn][3];

int main () {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, queries;
    cin >> n >> queries;
    while (queries--) {
        int l, r, c;
        cin >> l >> r >> c;
        pref[l][c-1]++;
        pref[r+1][c-1]--;
    }
    int ans = 0;
    for (int i=1; i<=n; i++) {
        for (int j: {0, 1, 2}) pref[i][j] += pref[i-1][j];
        if (pref[i][0] && pref[i][1] && !pref[i][2]) ans++;
    }
    cout << ans << "\n" ;
}