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
84
85
#include <iostream>
#include <string>
#include <cstring>

std::string split(std::string line, int word_index, char split = ' ')
{
    if(line.length() < 3 || word_index > line.length())
    {
        return "-1";
    }

    int c = 0;
    std::string to_return = "";

    for (int i = 0; i < line.length(); i++)
    {
        if (line[i] == split && c != word_index)
        {
            c++;
        }
        else if(c == word_index)
        {
            to_return += line[i];
        }
        else if (line[i] == split && c == word_index)
        {
            return to_return;
        }
    }

    return to_return;
}

int main()
{
    std::string line;

    getline(std::cin, line);

    int licz_puszek = stoi(split(line, 0)); //Liczba puszek
    int licz_operacji = stoi(split(line, 1)); //Liczba operacji

    char* puszkiR = new char[1000000];
    char* puszkiG = new char[1000000];
    char* puszkiB = new char[1000000];

    memset(puszkiR, '0', 1000000 * sizeof(*puszkiR));
    memset(puszkiG, '0', 1000000 * sizeof(*puszkiG));
    memset(puszkiB, '0', 1000000 * sizeof(*puszkiB));

    for (int i = 0; i < licz_operacji; i++)
    {
        getline(std::cin, line);

        char dye = split(line, 2)[0];
        int start = stoi(split(line, 0)) - 1;
        int len = stoi(split(line, 1)) - stoi(split(line, 0)) + 1;

        if (dye == '1')
        {
            memset(&puszkiR[start], '1', len * sizeof(*puszkiR));
        }
        else if (dye == '2')
        {
            memset(&puszkiG[start], '1', len * sizeof(*puszkiG));
        }
        else if (dye == '3')
        {
            memset(&puszkiB[start], '1', len * sizeof(*puszkiB));
        }
    }

    int c = 0;
    for (int i = 0; i < licz_puszek; i++)
    {
        if(puszkiR[i] == '1' && puszkiG[i] == '1' && puszkiB[i] == '0')
        {
            c++;
        }
    }

    std::cout << c;
    
    return 0;
}