// Potyczki20201B.cpp #include <iostream> #include <string.h> #include <fstream> #include <time.h> #define DEBUG false using namespace std; struct Puszka { bool colors[4] = {}; }; int task2() { int n, m; cin >> n >> m; Puszka *arr = new Puszka[n]; for (size_t i = 0; i < m; i++) { int l, r, k; cin >> l >> r >> k; for (; l <= r; l++) { arr[l].colors[k] = true; } } int sum = 0; for (size_t i = 0; i < n; i++) { if (arr[i].colors[1] && arr[i].colors[2] && !arr[i].colors[3]) sum++; } delete[] arr; return sum; } int main() { cout << task2(); }
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 | // Potyczki20201B.cpp #include <iostream> #include <string.h> #include <fstream> #include <time.h> #define DEBUG false using namespace std; struct Puszka { bool colors[4] = {}; }; int task2() { int n, m; cin >> n >> m; Puszka *arr = new Puszka[n]; for (size_t i = 0; i < m; i++) { int l, r, k; cin >> l >> r >> k; for (; l <= r; l++) { arr[l].colors[k] = true; } } int sum = 0; for (size_t i = 0; i < n; i++) { if (arr[i].colors[1] && arr[i].colors[2] && !arr[i].colors[3]) sum++; } delete[] arr; return sum; } int main() { cout << task2(); } |