#include <iostream> using namespace std; int main() { int canisterAmount = 0; int operationAmount = 0; cin >> canisterAmount >> operationAmount; bool array [canisterAmount][3]; for (int i = 0; i < canisterAmount; i++) for (int j = 0; j < 3; j++) array [ i ] [ j ] = false; for (int i = 0; i < operationAmount; i++) { int left = 0; int right = 0; int color = 0; cin >> left >> right >> color; left -= 1; right -= 1; for(int j = left; j <= right; j++) { array[j][color-1] = true; } } int counter = 0; for (int i = 0; i < canisterAmount; i++) { if(array[i][0] && array[i][1] && !array[i][2]) counter++; } cout << 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 34 35 36 37 | #include <iostream> using namespace std; int main() { int canisterAmount = 0; int operationAmount = 0; cin >> canisterAmount >> operationAmount; bool array [canisterAmount][3]; for (int i = 0; i < canisterAmount; i++) for (int j = 0; j < 3; j++) array [ i ] [ j ] = false; for (int i = 0; i < operationAmount; i++) { int left = 0; int right = 0; int color = 0; cin >> left >> right >> color; left -= 1; right -= 1; for(int j = left; j <= right; j++) { array[j][color-1] = true; } } int counter = 0; for (int i = 0; i < canisterAmount; i++) { if(array[i][0] && array[i][1] && !array[i][2]) counter++; } cout << counter; return 0; } |