#include <iostream> #include <vector> #include <set> using namespace std; int main() { int numberOfCans, numberOfMixes, left, right, color; cin >> numberOfCans; cin >> numberOfMixes; vector<set<int>> cans(numberOfCans); for (int i = 0; i < numberOfMixes; i++) { cin >> left; cin >> right; cin >> color; for (int j = left; j <= right; j++) cans[j - 1].insert(color); } int greenCans = 0; for (auto& can : cans) { if (can.size() == 2 && can.find(1) != can.end() && can.find(2) != can.end()) greenCans++; } cout << greenCans; 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 | #include <iostream> #include <vector> #include <set> using namespace std; int main() { int numberOfCans, numberOfMixes, left, right, color; cin >> numberOfCans; cin >> numberOfMixes; vector<set<int>> cans(numberOfCans); for (int i = 0; i < numberOfMixes; i++) { cin >> left; cin >> right; cin >> color; for (int j = left; j <= right; j++) cans[j - 1].insert(color); } int greenCans = 0; for (auto& can : cans) { if (can.size() == 2 && can.find(1) != can.end() && can.find(2) != can.end()) greenCans++; } cout << greenCans; return 0; } |