#include <iostream> using namespace std; class Can { public: Can() {} int numOfOps = 0; bool wasR = false, wasY = false, wasB = false; void push(short); bool isGreen(); }; void Can::push(short x) { if (wasR) return; numOfOps++; switch (x) { case 1: { wasY = true; break; } case 2: { wasB = true; break; } case 3: { wasR = true; break; } } } bool Can::isGreen(){ if (!wasR && numOfOps > 1 && wasB && wasY) return true; return false; } int main() { int n, m; cin >> n >> m; //n - puszki, m - operacje Can* row = new Can[n]; int l, r, k; for (int i = 0; i < m; i++) { cin >> l >> r >> k; l--; r--; for (l; l <= r; l++) { row[l].push(k); } } int gre = 0; for (int i = 0; i < m; i++) { if (row[i].isGreen()) gre++; } cout << gre; delete[] row; return 0; }
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 | #include <iostream> using namespace std; class Can { public: Can() {} int numOfOps = 0; bool wasR = false, wasY = false, wasB = false; void push(short); bool isGreen(); }; void Can::push(short x) { if (wasR) return; numOfOps++; switch (x) { case 1: { wasY = true; break; } case 2: { wasB = true; break; } case 3: { wasR = true; break; } } } bool Can::isGreen(){ if (!wasR && numOfOps > 1 && wasB && wasY) return true; return false; } int main() { int n, m; cin >> n >> m; //n - puszki, m - operacje Can* row = new Can[n]; int l, r, k; for (int i = 0; i < m; i++) { cin >> l >> r >> k; l--; r--; for (l; l <= r; l++) { row[l].push(k); } } int gre = 0; for (int i = 0; i < m; i++) { if (row[i].isGreen()) gre++; } cout << gre; delete[] row; return 0; } |