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
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;


#define REP(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)


int main() {
    int n, m;
    cin >> n >> m;
    vector<int> colors(n, 0);
    vector<int> painted[3];

    REP(j,m) {
        int l,r,k;
        cin >> l >> r >> k;
        l--; r--; k--;
        painted[k].push_back(2 * l);
        painted[k].push_back(2 * r + 1);
    }

    REP(k,3) {
        sort(painted[k].begin(), painted[k].end());
        int j = 0;
        int cnt = 0;
        REP(i,n) {
            while(j < painted[k].size() && painted[k][j] == 2*i) { cnt++; j++; }
            if(cnt > 0) colors[i] |= 1 << k;
            while(j < painted[k].size() && painted[k][j] == 2*i+1) { cnt--; j++; }
        }
    }

    int green = (1<<0) | (1<<1);  // for clarity
    int result = 0;
    REP(i,n) if(colors[i] == green) result++;
    cout << result << endl;
    return 0;
}