#include <iostream> #include <vector> using namespace std; struct Color { int y; int b; int r; Color(int y = 0, int b = 0, int r = 0) : y(y), b(b), r(r) {} Color mix(Color other) const { return Color(y + other.y, b + other.b, r + other.r); } bool is_yellow() const { return y > 0 && b == 0 && r == 0; } bool is_blue() const { return y == 0 && b > 0 && r == 0; } bool is_red() const { return y == 0 && b == 0 && r > 0; } bool is_green() { return y > 0 && b > 0 && r == 0; } bool is_orange() const { return y > 0 && b == 0 && r > 0; } bool is_purple() const { return y == 0 && b > 0 && r > 0; } bool is_brown() const { return y > 0 && b > 0 && r > 0; } int& operator[](const int index) { switch(index) { case 0: return y; case 1: return b; case 2: return r; } return r; } }; struct Event { Color begin; Color end; }; void solve(); vector<Event> read_events(const int can_count, const int operation_count); int main() { solve(); return 0; } void solve() { int can_count, operation_count; cin >> can_count >> operation_count; auto events = read_events(can_count, operation_count); Color color; int green_count = 0; for(const Event& event : events) { color = color.mix(event.end).mix(event.begin); if(color.is_green()) green_count++; } cout << green_count << endl; } vector<Event> read_events(const int can_count, const int operation_count) { vector<Event> events(can_count + 1); for(int i = 0; i < operation_count; i++) { int left, right, color_code; cin >> left >> right >> color_code; Color positive; positive[color_code - 1] = 1; events[left - 1].begin = events[left - 1].begin.mix(positive); Color negative; negative[color_code - 1] = -1; events[right].end = events[right].end.mix(negative); } return events; }
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 86 87 88 89 90 91 92 93 94 95 96 97 98 | #include <iostream> #include <vector> using namespace std; struct Color { int y; int b; int r; Color(int y = 0, int b = 0, int r = 0) : y(y), b(b), r(r) {} Color mix(Color other) const { return Color(y + other.y, b + other.b, r + other.r); } bool is_yellow() const { return y > 0 && b == 0 && r == 0; } bool is_blue() const { return y == 0 && b > 0 && r == 0; } bool is_red() const { return y == 0 && b == 0 && r > 0; } bool is_green() { return y > 0 && b > 0 && r == 0; } bool is_orange() const { return y > 0 && b == 0 && r > 0; } bool is_purple() const { return y == 0 && b > 0 && r > 0; } bool is_brown() const { return y > 0 && b > 0 && r > 0; } int& operator[](const int index) { switch(index) { case 0: return y; case 1: return b; case 2: return r; } return r; } }; struct Event { Color begin; Color end; }; void solve(); vector<Event> read_events(const int can_count, const int operation_count); int main() { solve(); return 0; } void solve() { int can_count, operation_count; cin >> can_count >> operation_count; auto events = read_events(can_count, operation_count); Color color; int green_count = 0; for(const Event& event : events) { color = color.mix(event.end).mix(event.begin); if(color.is_green()) green_count++; } cout << green_count << endl; } vector<Event> read_events(const int can_count, const int operation_count) { vector<Event> events(can_count + 1); for(int i = 0; i < operation_count; i++) { int left, right, color_code; cin >> left >> right >> color_code; Color positive; positive[color_code - 1] = 1; events[left - 1].begin = events[left - 1].begin.mix(positive); Color negative; negative[color_code - 1] = -1; events[right].end = events[right].end.mix(negative); } return events; } |