#include <cstdio> using namespace std; const int MX = 1e6; const int C = 3; int n, m, r, add[MX+1][C+1], sub[MX+1][C+1], now[C+1]; int main() { scanf("%d%d", &n, &m); while (m--) { int a, b, c; scanf("%d%d%d", &a, &b, &c); ++add[a][c]; ++sub[b][c]; } for (int i = 1; i <= n; ++i) { for (int c = 1; c <= C; ++c) now[c] += add[i][c]; if (now[1] && now[2] && !now[3]) ++r; for (int c = 1; c <= C; ++c) now[c] -= sub[i][c]; } printf("%d\n", r); 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 | #include <cstdio> using namespace std; const int MX = 1e6; const int C = 3; int n, m, r, add[MX+1][C+1], sub[MX+1][C+1], now[C+1]; int main() { scanf("%d%d", &n, &m); while (m--) { int a, b, c; scanf("%d%d%d", &a, &b, &c); ++add[a][c]; ++sub[b][c]; } for (int i = 1; i <= n; ++i) { for (int c = 1; c <= C; ++c) now[c] += add[i][c]; if (now[1] && now[2] && !now[3]) ++r; for (int c = 1; c <= C; ++c) now[c] -= sub[i][c]; } printf("%d\n", r); return 0; } |