#include <bits/stdc++.h> using namespace std; int col[1000002][3]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < m; i++) { int a, b, k; scanf("%d%d%d", &a, &b, &k); k--; col[a][k]++; col[b+1][k]--; } for (int i = 1; i <= n; i++) for (int k = 0; k < 2; k++) col[i][k] += col[i - 1][k]; int out = 0; for (int i = 1; i <= n; i++) { out += (col[i][0] > 0 && col[i][1] > 0 && col[i][2] == 0); } printf("%d\n", out); }
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 | #include <bits/stdc++.h> using namespace std; int col[1000002][3]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < m; i++) { int a, b, k; scanf("%d%d%d", &a, &b, &k); k--; col[a][k]++; col[b+1][k]--; } for (int i = 1; i <= n; i++) for (int k = 0; k < 2; k++) col[i][k] += col[i - 1][k]; int out = 0; for (int i = 1; i <= n; i++) { out += (col[i][0] > 0 && col[i][1] > 0 && col[i][2] == 0); } printf("%d\n", out); } |