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 <bits/stdc++.h>
#include <iostream>
using namespace std;
int n, m;
vector <pair <int, int>> k[3];
int pows[3] = {1, 2, 4};
int c[3], a, b, col;
int vals[1000002];
int main() {

    cin >> n >> m;

    while (m--) {
        cin >> a >> b >> col;
        k[col-1].push_back({a, b});
    }
    sort(k[0].begin(), k[0].end());
    sort(k[1].begin(), k[1].end());
    sort(k[2].begin(), k[2].end());
    for (int i = 0; i <= 2; i++) {
        for (pair<int, int> el : k[i]) {
            int start_i = max(el.first, c[i]);
            c[i] = max(el.second + 1, c[i]);
            for (int j = start_i; j <= el.second; j++) {
                vals[j] += pows[i];
            }
        }
    }
    int counter = 0;
    for (int i = 1; i <= n; i++) {
        if (vals[i] == 3) {
            counter++;
        }
    }
    cout << counter << endl;
    return 0;
}