#include <cstdio> int o[1000005][3], c[1000005][3]; int v[3], r; int main(){ int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < m; i++){ int l, r, k; scanf("%d%d%d", &l, &r, &k); k--; o[l][k]++; c[r][k]++; } for (int i = 1; i <= n; i++){ for (int j = 0; j < 3; j++){ v[j] += o[i][j]; } //printf("%d %d %d\n", v[0], v[1], v[2]); if ((v[0] > 0) && (v[1] > 0) && (v[2] == 0)){ r++; } for (int j = 0; j < 3; j++){ v[j] -= c[i][j]; } } printf("%d\n", r); }
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 | #include <cstdio> int o[1000005][3], c[1000005][3]; int v[3], r; int main(){ int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < m; i++){ int l, r, k; scanf("%d%d%d", &l, &r, &k); k--; o[l][k]++; c[r][k]++; } for (int i = 1; i <= n; i++){ for (int j = 0; j < 3; j++){ v[j] += o[i][j]; } //printf("%d %d %d\n", v[0], v[1], v[2]); if ((v[0] > 0) && (v[1] > 0) && (v[2] == 0)){ r++; } for (int j = 0; j < 3; j++){ v[j] -= c[i][j]; } } printf("%d\n", r); } |