#include <vector> #include <string> #include <iostream> #include <unordered_map> #include <algorithm> using namespace std; int main() { std::iostream::sync_with_stdio(false); int n, m; std::cin >> n; std::cin >> m; tuple<bool, bool, bool> *cans = new tuple<bool, bool, bool>[n]; vector<vector<int>> vect; while (m--) { int l,r,k; cin >> l; cin >> r; cin >> k; vect.push_back({l,r,k}); } for (auto val : vect) { int lValue = val[0] -1; int rValue = val[1] -1; int kValue = val[2]; for (int j = lValue; j <= rValue; j++) { if (kValue == 3) { cans[j] = tuple<bool, bool, bool>(get<0>(cans[j]), get<1>(cans[j]), get<2>(cans[j]) || true); } else if (kValue == 2) { cans[j] = tuple<bool, bool, bool>(get<0>(cans[j]), get<1>(cans[j]) || true, get<2>(cans[j])); } else { cans[j] = tuple<bool, bool, bool>(get<0>(cans[j]) || true, get<1>(cans[j]) , get<2>(cans[j])); } } } int result = 0; for (int i = 0; i < n; i++) { if (cans[i] == make_tuple(true, true, false)) { result++; } } cout << result; delete [] cans; 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 | #include <vector> #include <string> #include <iostream> #include <unordered_map> #include <algorithm> using namespace std; int main() { std::iostream::sync_with_stdio(false); int n, m; std::cin >> n; std::cin >> m; tuple<bool, bool, bool> *cans = new tuple<bool, bool, bool>[n]; vector<vector<int>> vect; while (m--) { int l,r,k; cin >> l; cin >> r; cin >> k; vect.push_back({l,r,k}); } for (auto val : vect) { int lValue = val[0] -1; int rValue = val[1] -1; int kValue = val[2]; for (int j = lValue; j <= rValue; j++) { if (kValue == 3) { cans[j] = tuple<bool, bool, bool>(get<0>(cans[j]), get<1>(cans[j]), get<2>(cans[j]) || true); } else if (kValue == 2) { cans[j] = tuple<bool, bool, bool>(get<0>(cans[j]), get<1>(cans[j]) || true, get<2>(cans[j])); } else { cans[j] = tuple<bool, bool, bool>(get<0>(cans[j]) || true, get<1>(cans[j]) , get<2>(cans[j])); } } } int result = 0; for (int i = 0; i < n; i++) { if (cans[i] == make_tuple(true, true, false)) { result++; } } cout << result; delete [] cans; return 0; } |