#include <iostream> #include <vector> #include <bitset> bool ContainsColor(const int can, const std::vector<std::pair<int, int>>& ranges) { for (auto& range : ranges) { if (can >= range.first && can <= range.second) return true; } return false; } int Count( const int n, std::vector<std::pair<int, int>>& y_ranges, std::vector<std::pair<int, int>>& b_ranges, std::vector<std::pair<int, int>>& r_ranges) { int count = 0; for (int i = 0; i < n; i++) { if (ContainsColor(i, y_ranges) && (ContainsColor(i, b_ranges) && !ContainsColor(i, r_ranges))) count++; } return count; } int main() { int n, m; std::cin >> n >> m; std::vector<std::pair<int, int>> y_ranges; std::vector<std::pair<int, int>> b_ranges; std::vector<std::pair<int, int>> r_ranges; for (int i = 0; i < m; i++) { int l, r, c; std::cin >> l >> r >> c; if (c == 1) y_ranges.push_back(std::pair<int, int>(l, r)); else if (c == 2) b_ranges.push_back(std::pair<int, int>(l, r)); else if (c == 3) r_ranges.push_back(std::pair<int, int>(l, r)); } std::cout << Count(n, y_ranges, b_ranges, r_ranges); 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 | #include <iostream> #include <vector> #include <bitset> bool ContainsColor(const int can, const std::vector<std::pair<int, int>>& ranges) { for (auto& range : ranges) { if (can >= range.first && can <= range.second) return true; } return false; } int Count( const int n, std::vector<std::pair<int, int>>& y_ranges, std::vector<std::pair<int, int>>& b_ranges, std::vector<std::pair<int, int>>& r_ranges) { int count = 0; for (int i = 0; i < n; i++) { if (ContainsColor(i, y_ranges) && (ContainsColor(i, b_ranges) && !ContainsColor(i, r_ranges))) count++; } return count; } int main() { int n, m; std::cin >> n >> m; std::vector<std::pair<int, int>> y_ranges; std::vector<std::pair<int, int>> b_ranges; std::vector<std::pair<int, int>> r_ranges; for (int i = 0; i < m; i++) { int l, r, c; std::cin >> l >> r >> c; if (c == 1) y_ranges.push_back(std::pair<int, int>(l, r)); else if (c == 2) b_ranges.push_back(std::pair<int, int>(l, r)); else if (c == 3) r_ranges.push_back(std::pair<int, int>(l, r)); } std::cout << Count(n, y_ranges, b_ranges, r_ranges); return 0; } |