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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
#include <cmath>

#define N 2000001

using namespace std;

unsigned int intervalTree[2 * N];
int n;
int m;

void updateInterval(unsigned int a, unsigned int b, unsigned int v) {
    while (a < b) {
        if (a % 2 == 1) {
            intervalTree[a] |= v;
            a += 1;
        }
        if(b % 2 == 0) {
            intervalTree[b] |= v;
            b -= 1;
        }
        a /= 2;
        b /= 2;
    }
    if (a == b) {
        intervalTree[a] |= v;
    }
}

int getValue(int a) {
    unsigned int res = 0;
    while (a > 0) {
        res |= intervalTree[a];
        a /= 2;
    }
    return res;
}

unsigned int get2Power(unsigned int k) {
    return 1 << k;
}

int main() {
    ios::sync_with_stdio(false);

    cin >> n >> m;
    int s = (int)log2(n - 1) + 1;
    for (int i = 0; i <= 2 * s; ++i) {
        intervalTree[i] = 0;
    }

    unsigned int b = get2Power(s);
    for(int i = 0; i < m; i++) {
        unsigned int l, r, k;
        cin >> l >> r >> k;

        unsigned int v = get2Power(k);
        updateInterval(b + l - 1, b + r - 1, v);
    }

    int count = 0;
    for (int i = b; i < b + n; ++i) {
        if (getValue(i) == 6) {
            count++;
        }
    }
    cout << count << endl;
}