#include <cstdio> #include <vector> using namespace std; int main() { int n, m; scanf("%d %d",&n, &m); vector<vector<int> > w(3, vector<int>(n+1)); for (int i = 0; i < m; i++) { int l,r,k; scanf("%d %d %d", &l, &r, &k); w[k-1][r]--; w[k-1][l-1]++; } vector<int> s(3); int ret = 0; for (int i = 0; i < n; i++) { s[0] += w[0][i]; s[1] += w[1][i]; s[2] += w[2][i]; if (s[0] > 0 && s[1] > 0 && s[2] == 0) { ret++; //printf("g %d\n", i+1); } } printf("%d\n", ret); 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 | #include <cstdio> #include <vector> using namespace std; int main() { int n, m; scanf("%d %d",&n, &m); vector<vector<int> > w(3, vector<int>(n+1)); for (int i = 0; i < m; i++) { int l,r,k; scanf("%d %d %d", &l, &r, &k); w[k-1][r]--; w[k-1][l-1]++; } vector<int> s(3); int ret = 0; for (int i = 0; i < n; i++) { s[0] += w[0][i]; s[1] += w[1][i]; s[2] += w[2][i]; if (s[0] > 0 && s[1] > 0 && s[2] == 0) { ret++; //printf("g %d\n", i+1); } } printf("%d\n", ret); return 0; } |