#include <iostream> #include <cstdio> #include <set> using namespace std; int colorCount[] = {0, 0, 0, 0}; int res = 0; struct cmp1 { bool operator()(const pair<int, pair<int, int>> &a, const pair<int, pair<int, int>> &b) const { return a.first < b.first; } }; struct cmp2 { bool operator()(const pair<int, pair<int, int>> &a, const pair<int, pair<int, int>> &b) const { return a.second.first < b.second.first; } }; multiset<pair<int, pair<int, int>>, cmp1> in; multiset<pair<int, pair<int, int>>, cmp2> out; int main() { ios_base::sync_with_stdio(0); int n, m; cin >> n >> m; for (int i = 0; i < m; ++i) { int l, r, k; cin >> l >> r >> k; in.insert(make_pair(l, make_pair(r, k))); } for (int i = 1; i <= n; ++i) { while (!out.empty()) { auto k = *out.begin(); if (k.second.first >= i) { break; } // cout << "(" << i << ")Farba out: " << k.first << " " << k.second.first << " " << k.second.second << endl; out.erase(out.begin()); colorCount[k.second.second]--; } while (!in.empty()) { auto k = *in.begin(); if (k.first > i) { break; } // cout << "(" << i << "Farba in: " << k.first << " " << k.second.first << " " << k.second.second << endl; in.erase(in.begin()); colorCount[k.second.second]++; out.insert(k); } // cout << "Kolory(" << i << ") " << colorCount[1] << " " << colorCount[2] << " " << colorCount[3] << endl; if (colorCount[1] > 0 && colorCount[2] > 0 && colorCount[3] <= 0) { res++; } } cout << res << '\n'; 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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | #include <iostream> #include <cstdio> #include <set> using namespace std; int colorCount[] = {0, 0, 0, 0}; int res = 0; struct cmp1 { bool operator()(const pair<int, pair<int, int>> &a, const pair<int, pair<int, int>> &b) const { return a.first < b.first; } }; struct cmp2 { bool operator()(const pair<int, pair<int, int>> &a, const pair<int, pair<int, int>> &b) const { return a.second.first < b.second.first; } }; multiset<pair<int, pair<int, int>>, cmp1> in; multiset<pair<int, pair<int, int>>, cmp2> out; int main() { ios_base::sync_with_stdio(0); int n, m; cin >> n >> m; for (int i = 0; i < m; ++i) { int l, r, k; cin >> l >> r >> k; in.insert(make_pair(l, make_pair(r, k))); } for (int i = 1; i <= n; ++i) { while (!out.empty()) { auto k = *out.begin(); if (k.second.first >= i) { break; } // cout << "(" << i << ")Farba out: " << k.first << " " << k.second.first << " " << k.second.second << endl; out.erase(out.begin()); colorCount[k.second.second]--; } while (!in.empty()) { auto k = *in.begin(); if (k.first > i) { break; } // cout << "(" << i << "Farba in: " << k.first << " " << k.second.first << " " << k.second.second << endl; in.erase(in.begin()); colorCount[k.second.second]++; out.insert(k); } // cout << "Kolory(" << i << ") " << colorCount[1] << " " << colorCount[2] << " " << colorCount[3] << endl; if (colorCount[1] > 0 && colorCount[2] > 0 && colorCount[3] <= 0) { res++; } } cout << res << '\n'; return 0; } |