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

int n, m, l, r, c;
set<int> yellow, blue, white, green;

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) white.insert(i);
    for (int i = 0; i < m; i++) {
        cin >> l >> r >> c;
        if (c == 1) { // yellow
            yellow.insert(white.lower_bound(l), white.upper_bound(r));
            white.erase(white.lower_bound(l), white.upper_bound(r));

            green.insert(blue.lower_bound(l), blue.upper_bound(r));
            blue.erase(blue.lower_bound(l), blue.upper_bound(r));
        } else if (c == 2) { // blue
            blue.insert(white.lower_bound(l), white.upper_bound(r));
            white.erase(white.lower_bound(l), white.upper_bound(r));

            green.insert(yellow.lower_bound(l), yellow.upper_bound(r));
            yellow.erase(yellow.lower_bound(l), yellow.upper_bound(r));
        } else { // red
            white.erase(white.lower_bound(l), white.upper_bound(r));
            yellow.erase(yellow.lower_bound(l), yellow.upper_bound(r));
            blue.erase(blue.lower_bound(l), blue.upper_bound(r));
            green.erase(green.lower_bound(l), green.upper_bound(r));
        }
    }

    cout << green.size() << '\n';
    return 0;
}