#include <iostream> #include <vector> int main() { int n, m, green = 0; std::cin >> n >> m; std::vector<int> color; while (n--) color.push_back(0); while (m--) { int l, r, k; std::cin >> l >> r >> k; // k 1-yellow 2-blue 3-red while (--r >= l-1) { if (color[r] == -1) continue; if (color[r] == 3 && k == 3) { color[r] = -1; green--; continue; } if (color[r] == 3) continue; if (k == 3) { color[r] = -1; continue; } if (color[r] == k) continue; if ( (color[r] == 1 && k == 2) || (color[r] == 2 && k == 1) ) { color[r] = 3; green++; continue; } color[r] += k; } } std::cout << green; 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 | #include <iostream> #include <vector> int main() { int n, m, green = 0; std::cin >> n >> m; std::vector<int> color; while (n--) color.push_back(0); while (m--) { int l, r, k; std::cin >> l >> r >> k; // k 1-yellow 2-blue 3-red while (--r >= l-1) { if (color[r] == -1) continue; if (color[r] == 3 && k == 3) { color[r] = -1; green--; continue; } if (color[r] == 3) continue; if (k == 3) { color[r] = -1; continue; } if (color[r] == k) continue; if ( (color[r] == 1 && k == 2) || (color[r] == 2 && k == 1) ) { color[r] = 3; green++; continue; } color[r] += k; } } std::cout << green; return 0; } |