#include <iostream> const int N = 1e6+3; int n, m, l, r, c; int beg[N][4], end[N][4]; int main() { std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cin >> n >> m; while (m--) { std::cin >> l >> r >> c; beg[l][c]++; end[r][c]++; } int cur[4] = {0, 0, 0, 0}; int res = 0; for (int i=1; i<=n; i++) { for (int c=1; c<=3; c++) cur[c] += beg[i][c]; if (cur[1] && cur[2] && !cur[3]) res++; for (int c=1; c<=3; c++) cur[c] -= end[i][c]; } std::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 | #include <iostream> const int N = 1e6+3; int n, m, l, r, c; int beg[N][4], end[N][4]; int main() { std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cin >> n >> m; while (m--) { std::cin >> l >> r >> c; beg[l][c]++; end[r][c]++; } int cur[4] = {0, 0, 0, 0}; int res = 0; for (int i=1; i<=n; i++) { for (int c=1; c<=3; c++) cur[c] += beg[i][c]; if (cur[1] && cur[2] && !cur[3]) res++; for (int c=1; c<=3; c++) cur[c] -= end[i][c]; } std::cout << res << "\n"; return 0; } |