#include <iostream> #include <vector> using namespace std; struct colors { bool used_colors[3] = { false }; //0 - żółty, 1 - niebieski, 2 - czerwony }; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n, m; cin >> n >> m; vector<colors> fence(n); int l, r, color; for (int i = 0; i < m; i++) { cin >> l >> r; l--; r--; cin >> color; color--; for (int j = l; j <= r; j++) { fence[j].used_colors[color] = true; } } int greens = 0; for (int i = 0; i < n; i++) { if (fence[i].used_colors[0] && fence[i].used_colors[1] && !fence[i].used_colors[2]) greens++; } cout << greens; 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 | #include <iostream> #include <vector> using namespace std; struct colors { bool used_colors[3] = { false }; //0 - żółty, 1 - niebieski, 2 - czerwony }; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n, m; cin >> n >> m; vector<colors> fence(n); int l, r, color; for (int i = 0; i < m; i++) { cin >> l >> r; l--; r--; cin >> color; color--; for (int j = l; j <= r; j++) { fence[j].used_colors[color] = true; } } int greens = 0; for (int i = 0; i < n; i++) { if (fence[i].used_colors[0] && fence[i].used_colors[1] && !fence[i].used_colors[2]) greens++; } cout << greens; return 0; } |