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
69
70
71
72
#include <iostream>
#include <vector>

void fastscan(int& number)
{
    bool negative = false;
    register int c;
    number = 0;
    c = getchar();
    if (c == '-')
    {
        negative = true;
        c = getchar();
    }
    for (; (c > 47 && c < 58); c = getchar())
        number = number * 10 + c - 48;
    if (negative)
        number *= -1;
}

class Infor {
public:
    int yellow = 0;
    int blue = 0;
    int red = 0;
};

int main()
{
    int n = 100000;
    int m = 100000;
    fastscan(n);
    fastscan(m);

    std::vector<Infor> cans(n + 1, Infor());

    int l = 1;
    int r = 3;
    int k = 1;

    for (int i = 0; i < m; i++) {
        fastscan(l);
        fastscan(r);
        fastscan(k);
        if (k == 1) {
            cans[l - 1].yellow++;
            cans[r].yellow--;
        }
        else if (k == 2) {
            cans[l - 1].blue++;
            cans[r].blue--;
        }
        else {
            cans[l - 1].red++;
            cans[r].red--;
        }
    }

    int sum = 0;
    int currentYellow = 0;
    int currentBlue = 0;
    int currentRed = 0;
    for (int i = 0; i < n; i++) {
        currentYellow += cans[i].yellow;
        currentBlue += cans[i].blue;
        currentRed += cans[i].red;
        if (currentYellow > 0 && currentBlue > 0 && currentRed == 0)
            sum++;
    }
    std::cout << sum;
    return 0;
}