#include <iostream> #include <vector> using namespace std; typedef unsigned long INT; /** Redirect stdin to provide input with Qt Creator */ void reopenInput(int argc, char** argv) { #ifdef LOCAL if (argc > 1) { auto inFile = argv[1]; cerr << "Reopening stdin to: " << inFile << endl; auto success = freopen(inFile, "r", stdin); if (!success) { cerr << "Error when opening file!" << endl; cerr << std::strerror(errno) << endl; } } #endif } struct Bucket { bool y, b, r = false; bool inline isGreen() { return y && b && !r; } }; int main(int argc, char** argv) { reopenInput(argc, argv); INT n, // buckets m; // operations cin >> n >> m; vector<Bucket> buckets(n + 1, Bucket()); cerr << "Buckets: " << n << endl; cerr << "Attempts: " << m << endl; for (INT i = 0; i < m; i++) { INT l, r, // bucket range indexed from 1 (!) k; // color ID cin >> l >> r >> k; for (INT j = l; j <= r; j++) { Bucket& buck = buckets[j]; switch (k) { case 1: // yellow buck.y = true; break; case 2: // blue buck.b = true; break; case 3: // red buck.r = true; break; } } } INT greenCount = 0; for (INT j = 1; j <= n; j++) { if (buckets[j].isGreen()) greenCount++; } cout << greenCount << endl; 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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | #include <iostream> #include <vector> using namespace std; typedef unsigned long INT; /** Redirect stdin to provide input with Qt Creator */ void reopenInput(int argc, char** argv) { #ifdef LOCAL if (argc > 1) { auto inFile = argv[1]; cerr << "Reopening stdin to: " << inFile << endl; auto success = freopen(inFile, "r", stdin); if (!success) { cerr << "Error when opening file!" << endl; cerr << std::strerror(errno) << endl; } } #endif } struct Bucket { bool y, b, r = false; bool inline isGreen() { return y && b && !r; } }; int main(int argc, char** argv) { reopenInput(argc, argv); INT n, // buckets m; // operations cin >> n >> m; vector<Bucket> buckets(n + 1, Bucket()); cerr << "Buckets: " << n << endl; cerr << "Attempts: " << m << endl; for (INT i = 0; i < m; i++) { INT l, r, // bucket range indexed from 1 (!) k; // color ID cin >> l >> r >> k; for (INT j = l; j <= r; j++) { Bucket& buck = buckets[j]; switch (k) { case 1: // yellow buck.y = true; break; case 2: // blue buck.b = true; break; case 3: // red buck.r = true; break; } } } INT greenCount = 0; for (INT j = 1; j <= n; j++) { if (buckets[j].isGreen()) greenCount++; } cout << greenCount << endl; return 0; } |