#include <iostream> #include <cstdio> #include <vector> #include <algorithm> using namespace std; int n, m, l, r, a, B, E, result; int tab[3][1000005]; vector < pair <int, int> > v[3]; int main () { scanf("%d%d", &n, &m); for (int i = 0; i < m; ++i) { scanf("%d%d%d", &l, &r, &a); v[a - 1].push_back(make_pair(l, r)); } for (int i = 0; i < 3; ++i) { v[i].push_back(make_pair(1000004, 1000004)); sort(v[i].begin(), v[i].end()); B = E = 0; m = v[i].size(); for (int j = 0; j < m; ++j) { if (v[i][j].first > E) { for (int k = B; k <= E; ++k) tab[i][k] = 1; B = v[i][j].first; E = v[i][j].second; } else if (v[i][j].second > E) E = v[i][j].second; } } for (int i = 1; i <= n; ++i) if (tab[0][i] == 1 && tab[1][i] == 1 && tab[2][i] == 0) result++; printf("%d\n", result); 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 | #include <iostream> #include <cstdio> #include <vector> #include <algorithm> using namespace std; int n, m, l, r, a, B, E, result; int tab[3][1000005]; vector < pair <int, int> > v[3]; int main () { scanf("%d%d", &n, &m); for (int i = 0; i < m; ++i) { scanf("%d%d%d", &l, &r, &a); v[a - 1].push_back(make_pair(l, r)); } for (int i = 0; i < 3; ++i) { v[i].push_back(make_pair(1000004, 1000004)); sort(v[i].begin(), v[i].end()); B = E = 0; m = v[i].size(); for (int j = 0; j < m; ++j) { if (v[i][j].first > E) { for (int k = B; k <= E; ++k) tab[i][k] = 1; B = v[i][j].first; E = v[i][j].second; } else if (v[i][j].second > E) E = v[i][j].second; } } for (int i = 1; i <= n; ++i) if (tab[0][i] == 1 && tab[1][i] == 1 && tab[2][i] == 0) result++; printf("%d\n", result); return 0; } |