#include <bits/stdc++.h> #include <iostream> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int32_t n; int32_t m; cin >> n; cin >> m; auto tab = new int32_t[1000002][3]; for (int i = 1; i <= n; i++) for (int j = 0; j < 3; j++) tab[i][j] = 0; int32_t l, r, k; while (m--) { cin >> l; cin >> r; cin >> k; --k; tab[l][k]++; tab[r + 1][k]--; } int32_t k0 = 0; int32_t k1 = 0; int32_t k2 = 0; int32_t greens = 0; for (int i = 1; i <= n; ++i) { k0 += tab[i][0]; k1 += tab[i][1]; k2 += tab[i][2]; if (k0 > 0 && k1 > 0 && k2 <= 0) ++greens; } cout << greens; 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 | #include <bits/stdc++.h> #include <iostream> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int32_t n; int32_t m; cin >> n; cin >> m; auto tab = new int32_t[1000002][3]; for (int i = 1; i <= n; i++) for (int j = 0; j < 3; j++) tab[i][j] = 0; int32_t l, r, k; while (m--) { cin >> l; cin >> r; cin >> k; --k; tab[l][k]++; tab[r + 1][k]--; } int32_t k0 = 0; int32_t k1 = 0; int32_t k2 = 0; int32_t greens = 0; for (int i = 1; i <= n; ++i) { k0 += tab[i][0]; k1 += tab[i][1]; k2 += tab[i][2]; if (k0 > 0 && k1 > 0 && k2 <= 0) ++greens; } cout << greens; return 0; } |