#include <iostream> #include <vector> #include <algorithm> using namespace std; int main(){ int n, m; cin >> n >> m; enum colours { yellow, blue, red }; // The innermost coordinate expresses a begun-ended ratio vector<vector<int>> tins(n + 1, vector<int>(3)); for (int i = 0; i < m; ++i){ int l,r,k; cin >> l >> r >> k; ++tins[l - 1][k-1]; --tins[r][k-1]; } int greenTinCount = 0; vector<int> currentColourRatio(3); for (int i = 0; i < n; ++i){ transform( currentColourRatio.begin(), currentColourRatio.end(), tins[i].begin(), currentColourRatio.begin(), plus<int>() ); if (currentColourRatio[red]){ continue; } if (currentColourRatio[yellow] && currentColourRatio[blue]){ ++greenTinCount; } } cout << greenTinCount << 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 | #include <iostream> #include <vector> #include <algorithm> using namespace std; int main(){ int n, m; cin >> n >> m; enum colours { yellow, blue, red }; // The innermost coordinate expresses a begun-ended ratio vector<vector<int>> tins(n + 1, vector<int>(3)); for (int i = 0; i < m; ++i){ int l,r,k; cin >> l >> r >> k; ++tins[l - 1][k-1]; --tins[r][k-1]; } int greenTinCount = 0; vector<int> currentColourRatio(3); for (int i = 0; i < n; ++i){ transform( currentColourRatio.begin(), currentColourRatio.end(), tins[i].begin(), currentColourRatio.begin(), plus<int>() ); if (currentColourRatio[red]){ continue; } if (currentColourRatio[yellow] && currentColourRatio[blue]){ ++greenTinCount; } } cout << greenTinCount << endl; return 0; } |