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

int main()
{
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    vector<tuple<int, int, int> > lrk;
    int* puszki = new int[1000010]();
    int n, m, l, r, k, zielony = 0;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> l >> r >> k;
        lrk.push_back(make_tuple(l, r, k)); //wczytanie l, r i k
    }

    for (int i = 0; i < lrk.size(); i++) {
        l = get<0>(lrk[i]);
        r = get<1>(lrk[i]);
        k = get<2>(lrk[i]);
        if (k == 1) {
            for (int j = l - 1; j < r; j++) {
                if (puszki[j] == 0)
                    puszki[j] = 1;
                else if (puszki[j] == 2) {
                    puszki[j] = 4;
                    zielony++;
                }
                else if (puszki[j] == 3)
                    puszki[j] = 5;
            }
        }
        else if (k == 2) {
            for (int j = l - 1; j < r; j++) {
                if (puszki[j] == 0)
                    puszki[j] = 2;
                else if (puszki[j] == 1) {
                    puszki[j] = 4;
                    zielony++;
                }
                else if (puszki[j] == 3)
                    puszki[j] = 6;
            }
        }
        else if (k == 3) {
            for (int j = l - 1; j < r; j++) {
                if (puszki[j] == 0)
                    puszki[j] = 3;
                else if (puszki[j] == 1)
                    puszki[j] = 5;
                else if (puszki[j] == 2)
                    puszki[j] = 6;
                else if (puszki[j] == 4) {
                    puszki[j] = 7;
                    zielony--;
                }
            }
        }
    }
    delete[] puszki;
    cout << zielony;
    return 0;
}