#include <iostream> #include <vector> #include <algorithm> struct Point { int pos; int col; int count; bool operator<(Point const& p) { return pos < p.pos; } }; int main() { std::ios::sync_with_stdio(false); int n, m; std::cin >> n >> m; std::vector<Point> v; for (int i = 0; i < m; ++i) { int l, r, k; std::cin >> l >> r >> k; v.push_back({l - 1, k - 1, 1}); v.push_back({r, k - 1, -1}); } std::sort(v.begin(), v.end()); std::vector<int> counts(3); auto it = v.begin(); int ret = 0; for (int i = 0; i < n; ++i) { while (it != v.end() && it->pos <= i) { counts[it->col] += it->count; it++; } if (counts[0] > 0 && counts[1] > 0 && counts[2] == 0) { ret++; } } std::cout << ret; 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 | #include <iostream> #include <vector> #include <algorithm> struct Point { int pos; int col; int count; bool operator<(Point const& p) { return pos < p.pos; } }; int main() { std::ios::sync_with_stdio(false); int n, m; std::cin >> n >> m; std::vector<Point> v; for (int i = 0; i < m; ++i) { int l, r, k; std::cin >> l >> r >> k; v.push_back({l - 1, k - 1, 1}); v.push_back({r, k - 1, -1}); } std::sort(v.begin(), v.end()); std::vector<int> counts(3); auto it = v.begin(); int ret = 0; for (int i = 0; i < n; ++i) { while (it != v.end() && it->pos <= i) { counts[it->col] += it->count; it++; } if (counts[0] > 0 && counts[1] > 0 && counts[2] == 0) { ret++; } } std::cout << ret; return 0; } |