#include <iostream> #include <cstdio> #include <vector> #include <algorithm> using namespace std; int main() { int cans, operations; scanf("%i %i", &cans, &operations); vector<int> paints[cans]; int start, stop, pigment; for(int i=0;i<operations;i++){ scanf("%i %i %i", &start, &stop, &pigment); for(int j=start;j<=stop;j++){ paints[j].push_back(pigment); } } int counter = 0; for(int i=0;i<cans;i++){ bool isYellow = find(paints[i].begin(), paints[i].end(), 1) != paints[i].end(); bool isBlue = find(paints[i].begin(), paints[i].end(), 2) != paints[i].end(); bool isRed = find(paints[i].begin(), paints[i].end(), 3) != paints[i].end(); if(isYellow && isBlue && !isRed){ counter++; } } printf ("%i", counter); 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 | #include <iostream> #include <cstdio> #include <vector> #include <algorithm> using namespace std; int main() { int cans, operations; scanf("%i %i", &cans, &operations); vector<int> paints[cans]; int start, stop, pigment; for(int i=0;i<operations;i++){ scanf("%i %i %i", &start, &stop, &pigment); for(int j=start;j<=stop;j++){ paints[j].push_back(pigment); } } int counter = 0; for(int i=0;i<cans;i++){ bool isYellow = find(paints[i].begin(), paints[i].end(), 1) != paints[i].end(); bool isBlue = find(paints[i].begin(), paints[i].end(), 2) != paints[i].end(); bool isRed = find(paints[i].begin(), paints[i].end(), 3) != paints[i].end(); if(isYellow && isBlue && !isRed){ counter++; } } printf ("%i", counter); return 0; } |