#include "bits/stdc++.h" using namespace std; vector <pair <int, int >> p1; vector <pair <int, int >> p2; vector <pair <int, int >> p3; vector <pair <int, int >> w1; vector <pair <int, int >> w2; vector <pair <int, int >> w3; vector <pair <int,int>> w; int main() { int n; int m; int l; int r; int k; int j = 0; int licznik = 0; ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; cin >> m; for (int i = 0; i < m; i++) { cin >> l; cin >> r; cin >> k; if (k == 1) p1.push_back(make_pair(l, r)); if (k == 2) p2.push_back(make_pair(l, r)); if (k == 3) p3.push_back(make_pair(l, r)); } sort(p1.begin(), p1.end()); sort(p2.begin(), p2.end()); sort(p3.begin(), p3.end()); if (p1.size() > 0) w1.push_back(make_pair(p1[0].first, p1[0].second)); if (p2.size() > 0) w2.push_back(make_pair(p2[0].first, p2[0].second)); if (p3.size() > 0) w3.push_back(make_pair(p3[0].first, p3[0].second)); if (p1.size() > 0) for (int i = 1; i < p1.size()+1; i++) { if (p1[i].first <= w1[j].second) w1[j].second = p1[i].second; else w1.push_back(make_pair(p1[i].first, p1[i].second)); } if (p2.size() > 0) for (int i = 1; i < p2.size()+1; i++) { if (p2[i].first <= w2[j].second) w2[j].second = p2[i].second; else w2.push_back(make_pair(p2[i].first, p2[i].second)); } if (p3.size() > 0) for (int i = 1; i < p3.size()+1; i++) { if (p3[i].first <= w3[j].second) w3[j].second = p3[i].second; else j++; w3.push_back(make_pair(p3[i].first, p3[i].second)); } w.reserve(n+1); w.push_back(make_pair(0, 0)); for (int i = 0; i < n; i++) w.push_back(make_pair(0, 0)); if (w1.size() > 0) for (int i = 0; i < w1.size(); i++) for (int y = w1[i].first; y <= w1[i].second; y++) { w[y].first += 1; w[y].second++; } if (w2.size()) for (int i = 0; i < w2.size(); i++) for (int y = w2[i].first; y <= w2[i].second; y++) { w[y].first += 2; w[y].second++; } if (w3.size()) for (int i = 0; i < w3.size(); i++) for (int y = w3[i].first; y <= w3[i].second; y++) { w[y].first += 3; w[y].second++; } for (int i = 1; i <= n; i++) cout << w[i].first << " " << w[i].second << '\n';//if (w[i].first == 3 && w[i].second == 2) licznik++; //cout << z; cout << licznik; exit(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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | #include "bits/stdc++.h" using namespace std; vector <pair <int, int >> p1; vector <pair <int, int >> p2; vector <pair <int, int >> p3; vector <pair <int, int >> w1; vector <pair <int, int >> w2; vector <pair <int, int >> w3; vector <pair <int,int>> w; int main() { int n; int m; int l; int r; int k; int j = 0; int licznik = 0; ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; cin >> m; for (int i = 0; i < m; i++) { cin >> l; cin >> r; cin >> k; if (k == 1) p1.push_back(make_pair(l, r)); if (k == 2) p2.push_back(make_pair(l, r)); if (k == 3) p3.push_back(make_pair(l, r)); } sort(p1.begin(), p1.end()); sort(p2.begin(), p2.end()); sort(p3.begin(), p3.end()); if (p1.size() > 0) w1.push_back(make_pair(p1[0].first, p1[0].second)); if (p2.size() > 0) w2.push_back(make_pair(p2[0].first, p2[0].second)); if (p3.size() > 0) w3.push_back(make_pair(p3[0].first, p3[0].second)); if (p1.size() > 0) for (int i = 1; i < p1.size()+1; i++) { if (p1[i].first <= w1[j].second) w1[j].second = p1[i].second; else w1.push_back(make_pair(p1[i].first, p1[i].second)); } if (p2.size() > 0) for (int i = 1; i < p2.size()+1; i++) { if (p2[i].first <= w2[j].second) w2[j].second = p2[i].second; else w2.push_back(make_pair(p2[i].first, p2[i].second)); } if (p3.size() > 0) for (int i = 1; i < p3.size()+1; i++) { if (p3[i].first <= w3[j].second) w3[j].second = p3[i].second; else j++; w3.push_back(make_pair(p3[i].first, p3[i].second)); } w.reserve(n+1); w.push_back(make_pair(0, 0)); for (int i = 0; i < n; i++) w.push_back(make_pair(0, 0)); if (w1.size() > 0) for (int i = 0; i < w1.size(); i++) for (int y = w1[i].first; y <= w1[i].second; y++) { w[y].first += 1; w[y].second++; } if (w2.size()) for (int i = 0; i < w2.size(); i++) for (int y = w2[i].first; y <= w2[i].second; y++) { w[y].first += 2; w[y].second++; } if (w3.size()) for (int i = 0; i < w3.size(); i++) for (int y = w3[i].first; y <= w3[i].second; y++) { w[y].first += 3; w[y].second++; } for (int i = 1; i <= n; i++) cout << w[i].first << " " << w[i].second << '\n';//if (w[i].first == 3 && w[i].second == 2) licznik++; //cout << z; cout << licznik; exit(0); } |