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



int main() {
    unordered_map<string, string> colors = {
            {"1", "Z"},
            {"2", "N"},
            {"3", "C"},
    };
    set<string> green_str = {"ZN", "NZ"};

    uint64_t total_green = 0;

    string input_info;
    getline(cin, input_info);
    istringstream iss(input_info);
    vector<string> data_lens{
        istream_iterator<string>{iss},
        istream_iterator<string>{}
    };
    vector<string> final_colors(stoi(data_lens[0]));
    vector<string> all_inputs;

    for(int i = 0; i < stoi(data_lens[1]); ++i) {
        string operation_info;
        getline(cin, operation_info);
        all_inputs.push_back(operation_info);
    }

    for (const auto& operation: all_inputs){
        istringstream is_str(operation);
        vector<string> new_range{
                istream_iterator<string>{is_str},
                istream_iterator<string>{}
        };
        for (int i = stoi(new_range[0]); i<=stoi(new_range[1]); i++){
            auto added_color = colors[new_range[2]];
            if (final_colors[i].find(added_color) == std::string::npos){
                final_colors[i].append(added_color);
            }
            else {
                continue;
            }
        }
    }
    for (const auto& color: final_colors) {
        if (green_str.count(color)) {
            total_green += 1;
        }
        else {
            continue;
        }
    }
    cout << total_green;
}