#include <bits/stdc++.h> const int MAX_N = 1e6; int t[5][MAX_N+3]; int main() { std::ios_base::sync_with_stdio(0); std::cin.tie(NULL); int n, m; std::cin >> n >> m; for (int i = 1; i <= m; i++) { int l, r; int k; std::cin >> l >> r >> k; t[k][l]++; t[k][r+1]--; } int res = 0; int sum1, sum2, sum3; sum1 = sum2 = sum3 = 0; for (int i = 1; i <= n; i++) { sum1 += t[1][i]; sum2 += t[2][i]; sum3 += t[3][i]; if (sum1 > 0 && sum2 > 0 && sum3 == 0) res++; } std::cout << res << "\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 | #include <bits/stdc++.h> const int MAX_N = 1e6; int t[5][MAX_N+3]; int main() { std::ios_base::sync_with_stdio(0); std::cin.tie(NULL); int n, m; std::cin >> n >> m; for (int i = 1; i <= m; i++) { int l, r; int k; std::cin >> l >> r >> k; t[k][l]++; t[k][r+1]--; } int res = 0; int sum1, sum2, sum3; sum1 = sum2 = sum3 = 0; for (int i = 1; i <= n; i++) { sum1 += t[1][i]; sum2 += t[2][i]; sum3 += t[3][i]; if (sum1 > 0 && sum2 > 0 && sum3 == 0) res++; } std::cout << res << "\n"; } |