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

using namespace std;

vector<vector<int>> in(4, vector<int> (1e6+5));

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int n, m, a, b, k, res = 0;
    cin >> n >> m;

    while(m --> 0) {
        cin >> a >> b >> k;
        in[k][a]++;
        in[k][b+1]--;
    }

    for(int i = 1;i <= n;++i) {
        in[1][i] += in[1][i-1], in[2][i] += in[2][i-1], in[3][i] += in[3][i-1];
        if(in[1][i] && in[2][i] && !in[3][i])
            ++res;
    }
    cout << res << "\n";
    return 0;
}