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
73
74
75
76
77
78
79
80
81
82
83
/* ==============================================================================
 *
 *  Author:
 *      Name:       Adam Jeliński
 *      Nickname:   charodziej <https://github.com/charodziej>
 *
 *  Created:        18:46 07.12.2020
 *
 *  b.cpp
 *
 *  g++ -std=c++17 -O3 -o b.o b.cpp
 *  ./b.o
 *
 * ============================================================================== */

#include <bits/stdc++.h>
using namespace std;

#ifndef DEBUG
#define DEBUG 0
#endif

#if DEBUG==1
#include "/home/charodziej/Documents/universal-print-in-cpp/lib/universal_print.h"
#else
#define watch(...)
#define watchb(...)
#define declare_struct(...)
namespace cupl{
    void showTypes(...){return;}
}
#endif

/* ============================================================================== *
 *     /\                   Please pardon the code above                   /\     *
 *     ||  It is necessary for the debugging library to function properly  ||     *
 * ============================================================================== */

typedef   signed long long  ll;
typedef unsigned long long ull;

vector<pair<int, char>> changes;

int main(){
#if DEBUG==0
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#endif

    int n, m;
    cin >> n >> m;

    for (int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;

        changes.push_back({ a, c });
        changes.push_back({ b + 1, -c });
    }
    int curr[3] = {0, 0, 0};

    sort(changes.begin(), changes.end());

    int loc = 0, res = 0;
    for (auto e : changes) {
        if (loc != e.first) {
            if (curr[0] > 0 && curr[1] > 0 && curr[2] == 0) {
                res++;
            }
            loc = e.first;
        }
        if (e.second < 0) {
            curr[-e.second - 1]--;
        } else {
            curr[e.second - 1]++;
        }
    }
    if (curr[0] > 0 && curr[1] > 0 && curr[2] == 0) {
        res++;
    }
    cout << res;
}