#include <iostream>
#include <set>
#include <vector>
using namespace std;
int main() {
int cansNum, specOperations, leftIndex, rightIndex, colour;
cin >> cansNum;
cin >> specOperations;
vector<set<int>> cans(cansNum);
for (int i = 0; i < specOperations; i++) {
cin >> leftIndex >> rightIndex >> colour;
for (int j = leftIndex; j <= rightIndex; j++) {
cans[j - 1].insert(colour);
}
}
int greenPaint = 0;
for (auto& can : cans) {
if (can.size() == 2 && can.find(2) != can.end() && can.find(1) != can.end()) {
greenPaint++;
}
}
cout << greenPaint;
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 | #include <iostream> #include <set> #include <vector> using namespace std; int main() { int cansNum, specOperations, leftIndex, rightIndex, colour; cin >> cansNum; cin >> specOperations; vector<set<int>> cans(cansNum); for (int i = 0; i < specOperations; i++) { cin >> leftIndex >> rightIndex >> colour; for (int j = leftIndex; j <= rightIndex; j++) { cans[j - 1].insert(colour); } } int greenPaint = 0; for (auto& can : cans) { if (can.size() == 2 && can.find(2) != can.end() && can.find(1) != can.end()) { greenPaint++; } } cout << greenPaint; return 0; } |
English