#include <bits/stdc++.h>
using namespace std;
constexpr int nax = 1e6, maxm = nax, pax = 3;
int n, m, tab[pax][nax];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for (int i = 0; i < m; ++i) {
int p, q, c; cin >> p >> q >> c;
--p, --q, --c;
++tab[c][p];
if (q + 1 < n)
--tab[c][q + 1];
}
for (int i = 1; i < n; ++i) {
for (int j = 0; j < pax; ++j) {
tab[j][i] += tab[j][i - 1];
}
}
int res = 0;
for (int i = 0; i < n; ++i) {
res += (tab[0][i] and tab[1][i] and not tab[2][i]);
}
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 29 30 31 32 33 34 | #include <bits/stdc++.h> using namespace std; constexpr int nax = 1e6, maxm = nax, pax = 3; int n, m, tab[pax][nax]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; for (int i = 0; i < m; ++i) { int p, q, c; cin >> p >> q >> c; --p, --q, --c; ++tab[c][p]; if (q + 1 < n) --tab[c][q + 1]; } for (int i = 1; i < n; ++i) { for (int j = 0; j < pax; ++j) { tab[j][i] += tab[j][i - 1]; } } int res = 0; for (int i = 0; i < n; ++i) { res += (tab[0][i] and tab[1][i] and not tab[2][i]); } cout << res << '\n'; } |
English