#include <bits/stdc++.h> using namespace std; template<typename T> T load() { auto value = T{}; cin >> value; return value; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); auto n = load<size_t>(); auto m = load<size_t>(); auto left_ends = vector<vector<unsigned>>(3, vector<unsigned>(n)); auto right_ends = vector<vector<unsigned>>(3, vector<unsigned>(n + 1)); for (size_t i = 0; i < m; i++) { auto l = load<size_t>(); auto r = load<size_t>(); auto k = load<size_t>(); left_ends[k - 1][l - 1] += 1; right_ends[k - 1][r] += 1; } auto result = 0; auto counter = array<size_t, 3>{0, 0, 0}; for (auto i = size_t{0}; i < n; i++) { for (auto j : {0, 1, 2}) { counter[j] += left_ends[j][i]; counter[j] -= right_ends[j][i]; } if (counter[0] > 0 && counter[1] > 0 && counter[2] == 0) { result += 1; } } cout << result << "\n"; }
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 | #include <bits/stdc++.h> using namespace std; template<typename T> T load() { auto value = T{}; cin >> value; return value; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); auto n = load<size_t>(); auto m = load<size_t>(); auto left_ends = vector<vector<unsigned>>(3, vector<unsigned>(n)); auto right_ends = vector<vector<unsigned>>(3, vector<unsigned>(n + 1)); for (size_t i = 0; i < m; i++) { auto l = load<size_t>(); auto r = load<size_t>(); auto k = load<size_t>(); left_ends[k - 1][l - 1] += 1; right_ends[k - 1][r] += 1; } auto result = 0; auto counter = array<size_t, 3>{0, 0, 0}; for (auto i = size_t{0}; i < n; i++) { for (auto j : {0, 1, 2}) { counter[j] += left_ends[j][i]; counter[j] -= right_ends[j][i]; } if (counter[0] > 0 && counter[1] > 0 && counter[2] == 0) { result += 1; } } cout << result << "\n"; } |